aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMatthew Gregan <[email protected]>2022-03-02 18:36:57 +1300
committerMatthew Gregan <[email protected]>2022-03-03 09:55:59 +1300
commitad99eeb273149559bb5f6e86ae9661532c3c8a51 (patch)
tree4bd7914a655b0b37c11c3084f625c00788d16191
parent11c0214f40cc7ddba2b8894ca49e871d230b47ad (diff)
downloadcubeb-ad99eeb273149559bb5f6e86ae9661532c3c8a51.tar.gz
cubeb-ad99eeb273149559bb5f6e86ae9661532c3c8a51.zip
owned_critical_section: Replace CRITICAL_SECTION with SRWLOCK on Windows.
-rw-r--r--src/cubeb_utils_win.h17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/cubeb_utils_win.h b/src/cubeb_utils_win.h
index 4c47f45..48e7b1b 100644
--- a/src/cubeb_utils_win.h
+++ b/src/cubeb_utils_win.h
@@ -11,24 +11,23 @@
#include "cubeb-internal.h"
#include <windows.h>
-/* This wraps a critical section to track the owner in debug mode, adapted from
+/* This wraps an SRWLock to track the owner in debug mode, adapted from
NSPR and http://blogs.msdn.com/b/oldnewthing/archive/2013/07/12/10433554.aspx
*/
class owned_critical_section {
public:
owned_critical_section()
+ : srwlock(SRWLOCK_INIT)
#ifndef NDEBUG
- : owner(0)
+ ,
+ owner(0)
#endif
{
- InitializeCriticalSection(&critical_section);
}
- ~owned_critical_section() { DeleteCriticalSection(&critical_section); }
-
void lock()
{
- EnterCriticalSection(&critical_section);
+ AcquireSRWLockExclusive(&srwlock);
#ifndef NDEBUG
XASSERT(owner != GetCurrentThreadId() && "recursive locking");
owner = GetCurrentThreadId();
@@ -41,7 +40,7 @@ public:
/* GetCurrentThreadId cannot return 0: it is not a the valid thread id */
owner = 0;
#endif
- LeaveCriticalSection(&critical_section);
+ ReleaseSRWLockExclusive(&srwlock);
}
/* This is guaranteed to have the good behaviour if it succeeds. The behaviour
@@ -55,12 +54,12 @@ public:
}
private:
- CRITICAL_SECTION critical_section;
+ SRWLOCK srwlock;
#ifndef NDEBUG
DWORD owner;
#endif
- // Disallow copy and assignment because CRICICAL_SECTION cannot be copied.
+ // Disallow copy and assignment because SRWLock cannot be copied.
owned_critical_section(const owned_critical_section &);
owned_critical_section & operator=(const owned_critical_section &);
};