summaryrefslogtreecommitdiff
path: root/src/thread/thread_win32.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/thread/thread_win32.cpp')
-rw-r--r--src/thread/thread_win32.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/thread/thread_win32.cpp b/src/thread/thread_win32.cpp
index 1e7d0731e..d002ddb88 100644
--- a/src/thread/thread_win32.cpp
+++ b/src/thread/thread_win32.cpp
@@ -108,9 +108,10 @@ class ThreadMutex_Win32 : public ThreadMutex {
private:
CRITICAL_SECTION critical_section; ///< The critical section we would enter.
HANDLE event; ///< Event for signalling.
+ uint recursive_count; ///< Recursive lock count.
public:
- ThreadMutex_Win32()
+ ThreadMutex_Win32() : recursive_count(0)
{
InitializeCriticalSection(&this->critical_section);
this->event = CreateEvent(NULL, FALSE, FALSE, NULL);
@@ -122,21 +123,30 @@ public:
CloseHandle(this->event);
}
- /* virtual */ void BeginCritical()
+ /* virtual */ void BeginCritical(bool allow_recursive = false)
{
+ /* windows mutex is recursive by itself */
EnterCriticalSection(&this->critical_section);
+ 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--;
LeaveCriticalSection(&this->critical_section);
}
/* 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();
WaitForSingleObject(this->event, INFINITE);
this->BeginCritical();
+ this->recursive_count = this->recursive_count;
}
/* virtual */ void SendSignal()