#ifndef __MUTEX_H
#define __MUTEX_H

#ifdef _WIN32

#include <windows.h>
#include <process.h>

#else

#include <pthread.h>

#endif


//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//
// CLASS Mutex
//
// This class is used manage concurrent access of different threads 
// to the worker threads job queue.
//
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

class Mutex 
{
friend class EventMutex;
private:

#ifdef _WIN32
    CRITICAL_SECTION _criticalSection;
#else
    pthread_mutex_t _criticalSection;
#endif

public:
         Mutex();
    void Lock();
    void Release();
};

//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//
// CLASS EventMutex
//
// This class implements an event/condition synchronization device. 
// Events are raised when certain conditions apply. 
//
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

class EventMutex 
{
private:

#ifdef _WIN32
    HANDLE _eventMutex;
#else
    pthread_cond_t _eventMutex;
#endif

public:
         EventMutex();
    void SignalEvent();
    void WaitForEvent( Mutex & mutex );
};

#endif 
