//////////////////////////////////////////////////////////////////////////////
//
// Asura_Platform_MultithreadTypes.h
//
// Copyright (c) 2006 Rebellion. All rights reserved.
//
// Description:
//
//     PC base classes to provide data for multithreading primitives
//
//////////////////////////////////////////////////////////////////////////////

// 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 PC
#include "Core/Asura_PlatformBasics.h"

typedef unsigned Asura_ThreadID;

class Asura_Platform_MutexData
{
public:

	Asura_Platform_MutexData()
    {
	    InitializeCriticalSection( &m_xCriticalSection );
    }

    ~Asura_Platform_MutexData()
    {
        DeleteCriticalSection( &m_xCriticalSection );
    }

protected:

	CRITICAL_SECTION m_xCriticalSection;
};


class Asura_Platform_SyncEvent
{
public:

	Asura_Platform_SyncEvent( const char* szName, bool bStartsSignalled )
	{
        // (MH - 30.05.2007) don't use szName to name the event as that leads
		// to multiple processes on the same PC sharing the event...
		m_xEventHandle = CreateEvent( NULL, true, bStartsSignalled, NULL );
	}

	~Asura_Platform_SyncEvent()
	{
		CloseHandle( m_xEventHandle );
	}

protected:

	HANDLE m_xEventHandle;
};

class Asura_Platform_Semaphore
{
public:

	Asura_Platform_Semaphore( const char* szName, u_int uInitialCount, u_int uMaxCount )
	{
		// KJFL - 22 April 2008 - as with the SyncEvent we don't pass the name as
		// the OS thinks instances sharing names to be the same semaphore - even
		// if the returned handle is different.
		m_xSemaphoreHandle = CreateSemaphore( NULL, uInitialCount, uMaxCount, NULL );
	}

	~Asura_Platform_Semaphore()
	{
		CloseHandle( m_xSemaphoreHandle );
	}

protected:

	HANDLE m_xSemaphoreHandle;
};

void Asura_PC_SetThreadName( const char* const szThreadName,
	const DWORD uThreadID = static_cast< DWORD >(-1) );

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

#endif // #ifndef ___ASURA_PLATFORM_MULTITHREADTYPES_H___
