File tree 2 files changed +30
-1
lines changed
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)
18
18
option (CMARK_STATIC "Build static libcmark-gfm library" ON )
19
19
option (CMARK_SHARED "Build shared libcmark-gfm library" ON )
20
20
option (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 )
22
22
23
23
add_subdirectory (src)
24
24
add_subdirectory (extensions)
Original file line number Diff line number Diff line change 5
5
6
6
#ifdef CMARK_THREADING
7
7
8
+ #if __has_include (< unistd .h > )
9
+ #include <unistd.h>
10
+ #endif
11
+
12
+ #if defined (_POSIX_THREADS )
13
+
8
14
#include <pthread.h>
9
15
10
16
#define CMARK_DEFINE_ONCE (NAME ) static pthread_once_t NAME##_once = PTHREAD_ONCE_INIT;
@@ -22,6 +28,29 @@ pthread_mutex_lock(&NAME##_lock);
22
28
23
29
#define CMARK_UNLOCK (NAME ) pthread_mutex_unlock(&NAME##_lock);
24
30
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
+
25
54
#else // no threading support
26
55
27
56
static CMARK_INLINE bool check_latch (int * latch ) {
You can’t perform that action at this time.
0 commit comments