diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /media/libcubeb/src/cubeb_utils_win.h | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'media/libcubeb/src/cubeb_utils_win.h')
-rw-r--r-- | media/libcubeb/src/cubeb_utils_win.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/media/libcubeb/src/cubeb_utils_win.h b/media/libcubeb/src/cubeb_utils_win.h new file mode 100644 index 0000000000..0112ad6d3c --- /dev/null +++ b/media/libcubeb/src/cubeb_utils_win.h @@ -0,0 +1,71 @@ +/* + * Copyright © 2016 Mozilla Foundation + * + * This program is made available under an ISC-style license. See the + * accompanying file LICENSE for details. + */ + +#if !defined(CUBEB_UTILS_WIN) +#define CUBEB_UTILS_WIN + +#include <windows.h> +#include "cubeb-internal.h" + +/* 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() +#ifndef NDEBUG + : owner(0) +#endif + { + InitializeCriticalSection(&critical_section); + } + + ~owned_critical_section() + { + DeleteCriticalSection(&critical_section); + } + + void lock() + { + EnterCriticalSection(&critical_section); +#ifndef NDEBUG + XASSERT(owner != GetCurrentThreadId() && "recursive locking"); + owner = GetCurrentThreadId(); +#endif + } + + void unlock() + { +#ifndef NDEBUG + /* GetCurrentThreadId cannot return 0: it is not a the valid thread id */ + owner = 0; +#endif + LeaveCriticalSection(&critical_section); + } + + /* This is guaranteed to have the good behaviour if it succeeds. The behaviour + is undefined otherwise. */ + void assert_current_thread_owns() + { +#ifndef NDEBUG + /* This implies owner != 0, because GetCurrentThreadId cannot return 0. */ + XASSERT(owner == GetCurrentThreadId()); +#endif + } + +private: + CRITICAL_SECTION critical_section; +#ifndef NDEBUG + DWORD owner; +#endif + + // 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&); +}; + +#endif /* CUBEB_UTILS_WIN */ |