Game Development Reference
In-Depth Information
How to do it...
1.
Let's create an API-independent abstraction to synchronize threads:
class Mutex
{
public:
Mutex()
{
#if defined( _WIN32 )
InitializeCriticalSection( &TheCS );
#else
pthread_mutex_init( &TheMutex, NULL );
#endif
}
~Mutex()
{
#if defined( _WIN32)
DeleteCriticalSection( &TheCS );
#else
pthread_mutex_destroy( &TheMutex );
#endif
}
2.
Locking and unlocking a mutex is also different in Windows and Android:
void Lock() const
{
#if defined( _WIN32 )
EnterCriticalSection( (CRITICAL_SECTION*)&TheCS );
#else
pthread_mutex_lock( &TheMutex );
#endif
}
void Unlock() const
{
#if defined( _WIN32 )
LeaveCriticalSection( (CRITICAL_SECTION*)&TheCS );
#else
pthread_mutex_unlock( &TheMutex );
#endif
}
#if defined( _WIN32 )
 
Search WWH ::




Custom Search