This source file includes following definitions.
- gl_get_setlocale_null_lock
- gl_get_setlocale_null_lock
- atomic_init
- gl_get_setlocale_null_lock
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21
22
23 #if OMIT_SETLOCALE_LOCK
24
25
26
27 typedef int dummy;
28
29 #else
30
31
32
33
34
35
36 # undef gl_get_setlocale_null_lock
37
38
39
40 # ifndef DLL_EXPORTED
41 # if HAVE_VISIBILITY
42
43 # define DLL_EXPORTED __attribute__((__visibility__("default")))
44 # elif defined _WIN32 || defined __CYGWIN__
45 # define DLL_EXPORTED __declspec(dllexport)
46 # else
47 # define DLL_EXPORTED
48 # endif
49 # endif
50
51 # if defined _WIN32 && !defined __CYGWIN__
52
53 # define WIN32_LEAN_AND_MEAN
54 # include <windows.h>
55
56 # include "windows-initguard.h"
57
58
59
60
61
62 DLL_EXPORTED CRITICAL_SECTION *gl_get_setlocale_null_lock (void);
63
64 static glwthread_initguard_t guard = GLWTHREAD_INITGUARD_INIT;
65 static CRITICAL_SECTION lock;
66
67
68 CRITICAL_SECTION *
69 gl_get_setlocale_null_lock (void)
70 {
71 if (!guard.done)
72 {
73 if (InterlockedIncrement (&guard.started) == 0)
74 {
75
76 InitializeCriticalSection (&lock);
77 guard.done = 1;
78 }
79 else
80 {
81
82 InterlockedDecrement (&guard.started);
83
84
85 while (!guard.done)
86 Sleep (0);
87 }
88 }
89 return &lock;
90 }
91
92 # elif HAVE_PTHREAD_API
93
94 # include <pthread.h>
95
96 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
97
98
99 DLL_EXPORTED pthread_mutex_t *gl_get_setlocale_null_lock (void);
100
101
102 pthread_mutex_t *
103 gl_get_setlocale_null_lock (void)
104 {
105 return &mutex;
106 }
107
108 # elif HAVE_THREADS_H
109
110 # include <threads.h>
111 # include <stdlib.h>
112
113 static int volatile init_needed = 1;
114 static once_flag init_once = ONCE_FLAG_INIT;
115 static mtx_t mutex;
116
117 static void
118 atomic_init (void)
119 {
120 if (mtx_init (&mutex, mtx_plain) != thrd_success)
121 abort ();
122 init_needed = 0;
123 }
124
125
126 DLL_EXPORTED mtx_t *gl_get_setlocale_null_lock (void);
127
128
129 mtx_t *
130 gl_get_setlocale_null_lock (void)
131 {
132 if (init_needed)
133 call_once (&init_once, atomic_init);
134 return &mutex;
135 }
136
137 # endif
138
139 # if (defined _WIN32 || defined __CYGWIN__) && !defined _MSC_VER
140
141
142 # if defined _WIN64 || defined _LP64
143 # define IMP(x) __imp_##x
144 # else
145 # define IMP(x) _imp__##x
146 # endif
147 void * IMP(gl_get_setlocale_null_lock) = &gl_get_setlocale_null_lock;
148 # endif
149
150 #endif