1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#if defined(WITH_THREADS)
#include "ThreadSync.h"
#if !defined(DEATH_TARGET_WINDOWS)
namespace nCine
{
///////////////////////////////////////////////////////////
// Mutex CLASS
///////////////////////////////////////////////////////////
Mutex::Mutex()
{
pthread_mutex_init(&mutex_, nullptr);
}
Mutex::~Mutex()
{
pthread_mutex_destroy(&mutex_);
}
void Mutex::Lock()
{
pthread_mutex_lock(&mutex_);
}
void Mutex::Unlock()
{
pthread_mutex_unlock(&mutex_);
}
int Mutex::TryLock()
{
return pthread_mutex_trylock(&mutex_);
}
///////////////////////////////////////////////////////////
// CondVariable CLASS
///////////////////////////////////////////////////////////
CondVariable::CondVariable()
{
pthread_cond_init(&cond_, nullptr);
}
CondVariable::~CondVariable()
{
pthread_cond_destroy(&cond_);
}
void CondVariable::Wait(Mutex& mutex)
{
pthread_cond_wait(&cond_, &(mutex.mutex_));
}
void CondVariable::Signal()
{
pthread_cond_signal(&cond_);
}
void CondVariable::Broadcast()
{
pthread_cond_broadcast(&cond_);
}
///////////////////////////////////////////////////////////
// ReadWriteLock CLASS
///////////////////////////////////////////////////////////
ReadWriteLock::ReadWriteLock()
{
pthread_rwlock_init(&rwlock_, nullptr);
}
ReadWriteLock::~ReadWriteLock()
{
pthread_rwlock_destroy(&rwlock_);
}
///////////////////////////////////////////////////////////
// Barrier CLASS
///////////////////////////////////////////////////////////
#if !defined(DEATH_TARGET_ANDROID) && !defined(DEATH_TARGET_APPLE)
Barrier::Barrier(std::uint32_t count)
{
pthread_barrier_init(&barrier_, nullptr, count);
}
Barrier::~Barrier()
{
pthread_barrier_destroy(&barrier_);
}
#endif
}
#endif
#endif
|