Initialize mutexes correctly on Windows
This commit is contained in:
parent
0da5d7f943
commit
c55e94e3f4
2 changed files with 13 additions and 7 deletions
|
@ -9,9 +9,9 @@ CC = x86_64-w64-mingw32-clang -std=c99 -c $(MANYWARNINGS) $(CCOPTS) -g
|
|||
INDULGENTCC = x86_64-w64-mingw32-clang -std=c99 -c $(FEWERWARNINGS) $(CCOPTS) -g
|
||||
|
||||
# Define the Windows platform preprocessor symbol
|
||||
CCOPTS = -DPLATFORM_WINDOWS=1
|
||||
MANYWARNINGS = -Weverything -Wno-pointer-arith -Wno-unused-macros -Wno-shadow -Wno-cast-align -Wno-variadic-macros -Wno-missing-noreturn -Wno-missing-prototypes -Wno-unused-parameter -Wno-padded -Wno-missing-variable-declarations -Wno-unreachable-code-break -Wno-class-varargs -Wno-format-nonliteral -Wno-cast-qual -Wno-double-promotion -Wno-comma -Wno-strict-prototypes -ferror-limit=1000
|
||||
FEWERWARNINGS = -Wno-implicit-int -Wno-dangling-else -Wno-pointer-sign -Wno-format-extra-args -Wno-tautological-compare -Wno-deprecated-declarations -Wno-logical-op-parentheses -Wno-format
|
||||
CCOPTS = -DPLATFORM_WINDOWS=1 -D_WIN32_WINNT=0x0600
|
||||
MANYWARNINGS = -Weverything -Wno-pointer-arith -Wno-unused-macros -Wno-shadow -Wno-cast-align -Wno-variadic-macros -Wno-missing-noreturn -Wno-missing-prototypes -Wno-unused-parameter -Wno-padded -Wno-missing-variable-declarations -Wno-unreachable-code-break -Wno-class-varargs -Wno-format-nonliteral -Wno-cast-qual -Wno-double-promotion -Wno-comma -Wno-strict-prototypes -Wno-extra-semi-stmt -ferror-limit=1000
|
||||
FEWERWARNINGS = -Wno-implicit-int -Wno-dangling-else -Wno-pointer-sign -Wno-format-extra-args -Wno-tautological-compare -Wno-deprecated-declarations -Wno-logical-op-parentheses -Wno-format -Wno-extra-semi-stmt
|
||||
|
||||
LINK = x86_64-w64-mingw32-clang $(CCOPTS) -g
|
||||
LINKEROPTS =
|
||||
|
|
|
@ -25,6 +25,7 @@ on a POSIX operating system.
|
|||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <shlobj.h>
|
||||
#undef IN
|
||||
#undef OUT
|
||||
|
||||
@ A Windows-safe form of |isdigit|. Annoyingly, the C specification allows
|
||||
|
@ -239,9 +240,14 @@ off_t Platform::size(char *transcoded_filename) {
|
|||
|
||||
@h Mutexes.
|
||||
|
||||
= (very early code)
|
||||
struct Win32_Mutex { INIT_ONCE init; CRITICAL_SECTION crit; };
|
||||
|
||||
@d CREATE_MUTEX(name)
|
||||
static LPCRITICAL_SECTION name = 0; if (name == 0) { name = malloc(sizeof (CRITICAL_SECTION)); InitializeCriticalSection(name); }
|
||||
static struct Win32_Mutex name = { INIT_ONCE_STATIC_INIT, { 0 }};
|
||||
@d GLOBAL_MUTEX(name)
|
||||
static LPCRITICAL_SECTION name = 0;
|
||||
@d LOCK_MUTEX(name) if (name == 0) { name = malloc(sizeof (CRITICAL_SECTION)); InitializeCriticalSection(name); } EnterCriticalSection(name)
|
||||
@d UNLOCK_MUTEX(name) LeaveCriticalSection(name)
|
||||
static struct Win32_Mutex name = { INIT_ONCE_STATIC_INIT, { 0 }};
|
||||
@d LOCK_MUTEX(name)
|
||||
{ BOOL pending; InitOnceBeginInitialize(&(name.init),0,&pending,0); if (pending) { InitializeCriticalSection(&(name.crit)); InitOnceComplete(&(name.init),0,0); } EnterCriticalSection(&(name.crit)); }
|
||||
@d UNLOCK_MUTEX(name)
|
||||
{ LeaveCriticalSection(&(name.crit)); }
|
||||
|
|
Loading…
Reference in a new issue