//////////////////////////////////////////////////////////////////////////////
//
// Asura_Platform_MultithreadTypes.h
//
// Copyright (c) 2006 Rebellion. All rights reserved.
//
//////////////////////////////////////////////////////////////////////////////

// B E G I N   F I L E   W R A P P E R ///////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef ASURA_PLATFORM_MULTITHREADTYPES_H___
#define ASURA_PLATFORM_MULTITHREADTYPES_H___ 1

// Asura
#include "Debugging/Asura_Assert.h"
#include "Core/Asura_Hash.h"

// PS2
#include <eekernel.h>

// D E F I N E S /////////////////////////////////////////////////////////////

#ifndef ASURA_PS2_THREAD_STACK_SIZE
#define ASURA_PS2_THREAD_STACK_SIZE (40960) //40*1024 - Same as PSP - Must be a multiple of 16
#endif

#ifndef ASURA_PS2_MAX_THREADS
#define ASURA_PS2_MAX_THREADS (0)
#endif

// T Y P E S /////////////////////////////////////////////////////////////////

typedef int Asura_ThreadID; // Taken from PSP. May need changing if/when this is all implemented properly.

// C L A S S E S /////////////////////////////////////////////////////////////

class Asura_Platform_MutexData
{

public:

	Asura_Platform_MutexData()
	{
		struct SemaParam xSemaParams = { 0, 1, 1, 0, 0, 0 };
		m_iSemaphoreId = CreateSema(&xSemaParams);
		Asura_Assert(m_iSemaphoreId >= 0, "CreateSema for mutex failed");
	}

	~Asura_Platform_MutexData()
	{
#ifdef ASURA_ASSERT
		int iRet = 
#endif
		DeleteSema(m_iSemaphoreId);
		Asura_Assert(iRet == m_iSemaphoreId, "DeleteSema for mutex failed");
	}

protected:

	int m_iSemaphoreId;

};


class Asura_Platform_SyncEvent
{
public:

	Asura_Platform_SyncEvent( const char* szName, bool bStartsSignalled )
	{
		int iInitCount = (bStartsSignalled) ? 1 : 0;
		struct SemaParam xSemaParams = { 0, 1, iInitCount, 0, 0, Asura_GetHashID(szName) };
		m_iSemaphoreId = CreateSema(&xSemaParams);
		Asura_Assert(m_iSemaphoreId >= 0, "CreateSema for sync event failed");
	}

	~Asura_Platform_SyncEvent()
	{
		if (m_iSemaphoreId >= 0)
		{
#ifdef ASURA_ASSERT
			int iRet = 
#endif
				DeleteSema(m_iSemaphoreId);
			Asura_Assert(iRet == m_iSemaphoreId, "DeleteSema for sync event failed");
		}
	}

protected:

	int m_iSemaphoreId;
};

class Asura_Platform_Semaphore
{
public:

	Asura_Platform_Semaphore( const char* szName, u_int uInitialCount, u_int uMaxCount )
	{
		// TODO 
	}

	~Asura_Platform_Semaphore()
	{
		// TODO 
	}

protected:


};


// E N D   F I L E   W R A P P E R ///////////////////////////////////////////

#endif // #ifndef ASURA_PLATFORM_MULTITHREADTYPES_H___
