#ifndef __HEAP_STRESS_H__
#define __HEAP_STRESS_H__

#include "continuation.h"
#include "timer.h"
#include "gpio.h"
#include "assertions.h"

DEFINE_THIS_FILE;

extern Heap FreeStore;

class HeapStressThread : public Continuation
{
	public:
		virtual bool Run(bool unUsed);

	private:
};

bool HeapStressThread::Run(bool unUsed)
{
	char* ptr[100];
    BEGIN();
	for (;;) {
		// Allocate 100 blocks of memory
		for (uint32_t i = 0; i < 100; i++) {
			ptr[i] = new char [100];
		}
		// ... and then release them
		for (uint32_t i = 0; i < 100; i++) {
			delete ptr[i];
		}
		// Let another thread grab the CPU
		YIELD();
		// Was the heap mangled?
		REQUIRE(!FreeStore.Damaged());
		// Let another thread grab the CPU
		YIELD();
	}
    END();
}
#endif // __FLASHER_H__
