- added safe mutex wrapper class

This commit is contained in:
Mark Vejvoda
2010-06-02 01:37:45 +00:00
parent bab0e87141
commit ace1cef8a8
6 changed files with 48 additions and 40 deletions

View File

@@ -51,7 +51,7 @@ private:
// class Mutex
// =====================================================
class Mutex{
class Mutex {
private:
SDL_mutex* mutex;
@@ -62,6 +62,28 @@ public:
void v();
};
class MutexSafeWrapper {
protected:
Mutex *mutex;
public:
MutexSafeWrapper(Mutex *mutex) {
this->mutex = mutex;
if(this->mutex != NULL) {
this->mutex->p();
}
}
~MutexSafeWrapper() {
ReleaseLock();
}
void ReleaseLock() {
if(this->mutex != NULL) {
this->mutex->v();
this->mutex = NULL;
}
}
};
// =====================================================
// class Semaphore
// =====================================================