mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-26 10:27:32 +09:00
import FIREFOX_52_6_0esr_RELEASE from mozilla-esr52 hg repo
This commit is contained in:
commit
dcd9973243
150858 changed files with 23884658 additions and 0 deletions
71
media/libcubeb/src/cubeb_utils_win.h
Normal file
71
media/libcubeb/src/cubeb_utils_win.h
Normal file
|
|
@ -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 enter()
|
||||
{
|
||||
EnterCriticalSection(&critical_section);
|
||||
#ifndef NDEBUG
|
||||
XASSERT(owner != GetCurrentThreadId() && "recursive locking");
|
||||
owner = GetCurrentThreadId();
|
||||
#endif
|
||||
}
|
||||
|
||||
void leave()
|
||||
{
|
||||
#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 */
|
||||
Loading…
Add table
Add a link
Reference in a new issue