summaryrefslogtreecommitdiff
path: root/src/thread/thread_os2.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2014-02-16 21:37:05 +0000
committerfrosch <frosch@openttd.org>2014-02-16 21:37:05 +0000
commit7ac18c0f22bcd62feede693be2617264eb5decf6 (patch)
tree9e19c462079a70919f6fa2c9616b04639251cbe8 /src/thread/thread_os2.cpp
parentb2ca2e297933c52e42f74b51c3f59b024ccb3772 (diff)
downloadopenttd-7ac18c0f22bcd62feede693be2617264eb5decf6.tar.xz
(svn r26349) -Add: Optional recursive locking of mutexes.
Diffstat (limited to 'src/thread/thread_os2.cpp')
-rw-r--r--src/thread/thread_os2.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/thread/thread_os2.cpp b/src/thread/thread_os2.cpp
index 903ea0ebe..56f86275d 100644
--- a/src/thread/thread_os2.cpp
+++ b/src/thread/thread_os2.cpp
@@ -95,9 +95,10 @@ class ThreadMutex_OS2 : public ThreadMutex {
private:
HMTX mutex; ///< The mutex.
HEV event; ///< Event for waiting.
+ uint recursive_count; ///< Recursive lock count.
public:
- ThreadMutex_OS2()
+ ThreadMutex_OS2() : recursive_count(0)
{
DosCreateMutexSem(NULL, &mutex, 0, FALSE);
DosCreateEventSem(NULL, &event, 0, FALSE);
@@ -109,21 +110,30 @@ public:
DosCloseEventSem(event);
}
- /* virtual */ void BeginCritical()
+ /* virtual */ void BeginCritical(bool allow_recursive = false)
{
+ /* os2 mutex is recursive by itself */
DosRequestMutexSem(mutex, (unsigned long) SEM_INDEFINITE_WAIT);
+ this->recursive_count++;
+ if (!allow_recursive && this->recursive_count != 1) NOT_REACHED();
}
- /* virtual */ void EndCritical()
+ /* virtual */ void EndCritical(bool allow_recursive = false)
{
+ if (!allow_recursive && this->recursive_count != 1) NOT_REACHED();
+ this->recursive_count--;
DosReleaseMutexSem(mutex);
}
/* virtual */ void WaitForSignal()
{
+ assert(this->recursive_count == 1); // Do we need to call Begin/EndCritical multiple times otherwise?
+ uint old_recursive_count = this->recursive_count;
+ this->recursive_count = 0;
this->EndCritical();
DosWaitEventSem(event, SEM_INDEFINITE_WAIT);
this->BeginCritical();
+ this->recursive_count = this->recursive_count;
}
/* virtual */ void SendSignal()