File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ option(CMARK_TESTS "Build cmark-gfm tests and enable testing" ON)
1818option (CMARK_STATIC "Build static libcmark-gfm library" ON )
1919option (CMARK_SHARED "Build shared libcmark-gfm library" ON )
2020option (CMARK_LIB_FUZZER "Build libFuzzer fuzzing harness" OFF )
21- option (CMARK_THREADING "Add locks around static accesses via pthreads " OFF )
21+ option (CMARK_THREADING "Add locks around static accesses" OFF )
2222
2323add_subdirectory (src)
2424add_subdirectory (extensions)
Original file line number Diff line number Diff line change 55
66#ifdef CMARK_THREADING
77
8+ #if __has_include (< unistd .h > )
9+ #include <unistd.h>
10+ #endif
11+
12+ #if defined (_POSIX_THREADS )
13+
814#include <pthread.h>
915
1016#define CMARK_DEFINE_ONCE (NAME ) static pthread_once_t NAME##_once = PTHREAD_ONCE_INIT;
@@ -22,6 +28,29 @@ pthread_mutex_lock(&NAME##_lock);
2228
2329#define CMARK_UNLOCK (NAME ) pthread_mutex_unlock(&NAME##_lock);
2430
31+ #elif defined(_WIN32 ) // building for windows
32+
33+ #define _WIN32_WINNT 0x0600
34+ #include <synchapi.h>
35+
36+ #define CMARK_DEFINE_ONCE (NAME ) static INIT_ONCE NAME##_once = INIT_ONCE_STATIC_INIT;
37+
38+ #define CMARK_RUN_ONCE (NAME , FUNC ) do { \
39+ BOOL fStatus; BOOL fPending; \
40+ fStatus = InitOnceBeginInitialize(&NAME##_once, 0, &fPending, NULL); \
41+ if (!fStatus || !fPending) break; \
42+ FUNC(); \
43+ InitOnceComplete(&NAME##_once, 0, NULL); \
44+ } while (0);
45+
46+ #define CMARK_DEFINE_LOCK (NAME ) static SRWLOCK NAME##_lock = SRWLOCK_INIT;
47+
48+ #define CMARK_INITIALIZE_AND_LOCK (NAME ) AcquireSRWLockExclusive(&NAME##_lock);
49+
50+ #define CMARK_UNLOCK (NAME ) ReleaseSRWLockExclusive(&NAME##_lock);
51+
52+ #endif
53+
2554#else // no threading support
2655
2756static CMARK_INLINE bool check_latch (int * latch ) {
You can’t perform that action at this time.
0 commit comments