1
0
Fork 0

(svn r26342) -Add: A mutex locker class.

release/1.4
fonsinchen 2014-02-16 16:24:41 +00:00
parent 2945e76269
commit dc0f89b7e9
1 changed files with 22 additions and 0 deletions

View File

@ -88,6 +88,28 @@ public:
virtual void SendSignal() = 0; virtual void SendSignal() = 0;
}; };
/**
* Simple mutex locker to keep a mutex locked until the locker goes out of scope.
*/
class ThreadMutexLocker {
public:
/**
* Lock the mutex and keep it locked for the life time of this object.
* @param mutex Mutex to be locked.
*/
ThreadMutexLocker(ThreadMutex *mutex) : mutex(mutex) { mutex->BeginCritical(); }
/**
* Unlock the mutex.
*/
~ThreadMutexLocker() { this->mutex->EndCritical(); }
private:
ThreadMutexLocker(const ThreadMutexLocker &) { NOT_REACHED(); }
ThreadMutexLocker &operator=(const ThreadMutexLocker &) { NOT_REACHED(); return *this; }
ThreadMutex *mutex;
};
/** /**
* Get number of processor cores in the system, including HyperThreading or similar. * Get number of processor cores in the system, including HyperThreading or similar.
* @return Total number of processor cores. * @return Total number of processor cores.