#include <ZUtil/ZConcurrency.hpp>
#include <SST/SST_Concurrency.h>

ZThreadContext ZConcurrency::CreateThread(int(*_func)(void*), void *_arg)
{
	ZThreadContext context;

	context.Thread = SST_Concurrency_CreateThread(_func, _arg);
	
	//TODO - this doesn't install the running thread id, just this current thread id
	//bleargh
	//context.ThreadId = SST_Concurrency_GetThreadId();

	return context;
}

void ZConcurrency::DestroyThread(ZThreadContext& _context)
{
	SST_Concurrency_DestroyThread(_context.Thread);

	_context.Thread = NULL;
	_context.ThreadId = 0;
	_context.ThreadExitStatus = 0;
}

void ZConcurrency::SleepThread(uint32_t _ms)
{
	SST_Concurrency_SleepThread(_ms);
}

uint32_t ZConcurrency::GetThreadId()
{
	return SST_Concurrency_GetThreadId();
}

uint64_t ZConcurrency::GetTicks()
{
	return SST_Concurrency_GetTicks();
}

bool ZConcurrency::WaitThread(ZThreadContext& _context)
{
	return SST_Concurrency_WaitThread(_context.Thread, &_context.ThreadExitStatus) != 0;
}

void ZConcurrency::YieldThread()
{
	SST_Concurrency_YieldThread();
}

