#ifndef __CMutex__H_
#define __CMutex__H_
#include "common.h"
class CMutex
{
public:
CMutex();
~CMutex();
void Lock();
void UnLock();
public:
#if defined(WIN32) || defined(_WIN32)
#elif __linux__
pthread_mutex_t* GetMutex() {
return &m_mutex;
}
#endif
private:
#if defined(WIN32) || defined(_WIN32)
CRITICAL_SECTION m_Cs;
#elif __linux__
pthread_mutex_t m_mutex;
#endif
};
#endif
#include "stdafx.h"
#include "CMutex.h"
CMutex::CMutex()
{
#if defined(WIN32) || defined(_WIN32)
InitializeCriticalSection(&m_Cs);
#elif __linux__
pthread_mutex_init(&m_mutex, NULL);
#endif
}
CMutex::~CMutex()
{
#if defined(WIN32) || defined(_WIN32)
DeleteCriticalSection(&m_Cs);
#elif __linux__
pthread_mutex_destroy(&m_mutex);
#endif
}
void CMutex::Lock()
{
#if defined(WIN32) || defined(_WIN32)
EnterCriticalSection(&m_Cs);
#elif __linux__
pthread_mutex_lock(&m_mutex);
#endif
}
void CMutex::UnLock()
{
#if defined(WIN32) || defined(_WIN32)
LeaveCriticalSection(&m_Cs);
#elif __linux__
pthread_mutex_unlock(&m_mutex);
#endif
}