early-access version 2840

This commit is contained in:
pineappleEA
2022-07-17 09:10:25 +02:00
parent b866bff3f2
commit e8706a3c92
77 changed files with 2720 additions and 1054 deletions

View File

@@ -11,23 +11,24 @@
#include "cubeb-internal.h"
#include <windows.h>
/* This wraps an SRWLock to track the owner in debug mode, adapted from
/* This wraps a critical section 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()
{
AcquireSRWLockExclusive(&srwlock);
EnterCriticalSection(&critical_section);
#ifndef NDEBUG
XASSERT(owner != GetCurrentThreadId() && "recursive locking");
owner = GetCurrentThreadId();
@@ -40,7 +41,7 @@ public:
/* GetCurrentThreadId cannot return 0: it is not a the valid thread id */
owner = 0;
#endif
ReleaseSRWLockExclusive(&srwlock);
LeaveCriticalSection(&critical_section);
}
/* This is guaranteed to have the good behaviour if it succeeds. The behaviour
@@ -54,12 +55,12 @@ public:
}
private:
SRWLOCK srwlock;
CRITICAL_SECTION critical_section;
#ifndef NDEBUG
DWORD owner;
#endif
// Disallow copy and assignment because SRWLock cannot be copied.
// Disallow copy and assignment because CRICICAL_SECTION cannot be copied.
owned_critical_section(const owned_critical_section &);
owned_critical_section & operator=(const owned_critical_section &);
};