mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-17 21:25:40 +00:00
(svn r26342) -Add: A mutex locker class.
This commit is contained in:
parent
537975b794
commit
3bd62321dc
@ -88,6 +88,28 @@ public:
|
||||
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.
|
||||
* @return Total number of processor cores.
|
||||
|
Loading…
Reference in New Issue
Block a user