@@ -147,6 +147,49 @@ LDi_mutex_init_imp(ld_mutex_t *const mutex)
147147 return status == 0 ;
148148}
149149
150+ static bool
151+ LDi_mutex_init_nl_imp (ld_mutex_t * const mutex )
152+ {
153+ int status ;
154+
155+ #ifndef _WIN32
156+ pthread_mutexattr_t attributes ;
157+ int kind ;
158+ #endif
159+
160+ #ifdef _WIN32
161+ InitializeCriticalSection (mutex );
162+
163+ status = 0 ;
164+ #else
165+ if ((status = pthread_mutexattr_init (& attributes )) != 0 ) {
166+ goto done ;
167+ }
168+
169+ #ifdef LAUNCHDARKLY_CONCURRENCY_UNSAFE
170+ kind = PTHREAD_MUTEX_NORMAL ;
171+ #else
172+ kind = PTHREAD_MUTEX_ERRORCHECK ;
173+ #endif
174+
175+ if ((status = pthread_mutexattr_settype (& attributes , kind )) != 0 ) {
176+ goto done ;
177+ }
178+
179+ if ((status = pthread_mutex_init (mutex , & attributes )) != 0 ) {
180+ goto done ;
181+ }
182+
183+ /* this should never fail */
184+ if ((status = pthread_mutexattr_destroy (& attributes )) != 0 ) {
185+ goto done ;
186+ }
187+ #endif
188+
189+ done :
190+ return status == 0 ;
191+ }
192+
150193static bool
151194LDi_mutex_destroy_imp (ld_mutex_t * const mutex )
152195{
@@ -180,6 +223,22 @@ LDi_mutex_destroy_imp(ld_mutex_t *const mutex)
180223 return status == 0 ;
181224}
182225
226+ static bool
227+ LDi_mutex_destroy_nl_imp (ld_mutex_t * const mutex )
228+ {
229+ int status ;
230+
231+ #ifdef _WIN32
232+ DeleteCriticalSection (mutex );
233+
234+ status = 0 ;
235+ #else
236+ status = pthread_mutex_destroy (mutex );
237+ #endif
238+
239+ return status == 0 ;
240+ }
241+
183242static bool
184243LDi_mutex_lock_imp (ld_mutex_t * const mutex )
185244{
@@ -213,6 +272,22 @@ LDi_mutex_lock_imp(ld_mutex_t *const mutex)
213272 return status == 0 ;
214273}
215274
275+ static bool
276+ LDi_mutex_lock_nl_imp (ld_mutex_t * const mutex )
277+ {
278+ int status ;
279+
280+ #ifdef _WIN32
281+ EnterCriticalSection (mutex );
282+
283+ status = 0 ;
284+ #else
285+ status = pthread_mutex_lock (mutex );
286+ #endif
287+
288+ return status == 0 ;
289+ }
290+
216291static bool
217292LDi_mutex_unlock_imp (ld_mutex_t * const mutex )
218293{
@@ -246,6 +321,22 @@ LDi_mutex_unlock_imp(ld_mutex_t *const mutex)
246321 return status == 0 ;
247322}
248323
324+ static bool
325+ LDi_mutex_unlock_nl_imp (ld_mutex_t * const mutex )
326+ {
327+ int status ;
328+
329+ #ifdef _WIN32
330+ LeaveCriticalSection (mutex );
331+
332+ status = 0 ;
333+ #else
334+ status = pthread_mutex_unlock (mutex );
335+ #endif
336+
337+ return status == 0 ;
338+ }
339+
249340static bool
250341LDi_rwlock_init_imp (ld_rwlock_t * const lock )
251342{
@@ -631,22 +722,27 @@ LDi_cond_init_imp(ld_cond_t *const cond)
631722 return status == 0 ;
632723}
633724
634- ld_mutex_unary_t LDi_mutex_init = LDi_mutex_init_imp ;
635- ld_mutex_unary_t LDi_mutex_destroy = LDi_mutex_destroy_imp ;
636- ld_mutex_unary_t LDi_mutex_lock = LDi_mutex_lock_imp ;
637- ld_mutex_unary_t LDi_mutex_unlock = LDi_mutex_unlock_imp ;
638-
639- ld_thread_join_t LDi_thread_join = LDi_thread_join_imp ;
640- ld_thread_create_t LDi_thread_create = LDi_thread_create_imp ;
641-
642- ld_rwlock_unary_t LDi_rwlock_init = LDi_rwlock_init_imp ;
643- ld_rwlock_unary_t LDi_rwlock_destroy = LDi_rwlock_destroy_imp ;
644- ld_rwlock_unary_t LDi_rwlock_rdlock = LDi_rwlock_rdlock_imp ;
645- ld_rwlock_unary_t LDi_rwlock_wrlock = LDi_rwlock_wrlock_imp ;
646- ld_rwlock_unary_t LDi_rwlock_rdunlock = LDi_rwlock_rdunlock_imp ;
647- ld_rwlock_unary_t LDi_rwlock_wrunlock = LDi_rwlock_wrunlock_imp ;
648-
649- ld_cond_unary_t LDi_cond_init = LDi_cond_init_imp ;
650- ld_cond_wait_t LDi_cond_wait = LDi_cond_wait_imp ;
651- ld_cond_unary_t LDi_cond_signal = LDi_cond_signal_imp ;
652- ld_cond_unary_t LDi_cond_destroy = LDi_cond_destroy_imp ;
725+ ld_mutex_unary_t LDi_mutex_init = LDi_mutex_init_imp ;
726+ ld_mutex_unary_t LDi_mutex_destroy = LDi_mutex_destroy_imp ;
727+ ld_mutex_unary_t LDi_mutex_lock = LDi_mutex_lock_imp ;
728+ ld_mutex_unary_t LDi_mutex_unlock = LDi_mutex_unlock_imp ;
729+
730+ ld_mutex_unary_t LDi_mutex_nl_init = LDi_mutex_init_nl_imp ;
731+ ld_mutex_unary_t LDi_mutex_nl_destroy = LDi_mutex_destroy_nl_imp ;
732+ ld_mutex_unary_t LDi_mutex_nl_lock = LDi_mutex_lock_nl_imp ;
733+ ld_mutex_unary_t LDi_mutex_nl_unlock = LDi_mutex_unlock_nl_imp ;
734+
735+ ld_thread_join_t LDi_thread_join = LDi_thread_join_imp ;
736+ ld_thread_create_t LDi_thread_create = LDi_thread_create_imp ;
737+
738+ ld_rwlock_unary_t LDi_rwlock_init = LDi_rwlock_init_imp ;
739+ ld_rwlock_unary_t LDi_rwlock_destroy = LDi_rwlock_destroy_imp ;
740+ ld_rwlock_unary_t LDi_rwlock_rdlock = LDi_rwlock_rdlock_imp ;
741+ ld_rwlock_unary_t LDi_rwlock_wrlock = LDi_rwlock_wrlock_imp ;
742+ ld_rwlock_unary_t LDi_rwlock_rdunlock = LDi_rwlock_rdunlock_imp ;
743+ ld_rwlock_unary_t LDi_rwlock_wrunlock = LDi_rwlock_wrunlock_imp ;
744+
745+ ld_cond_unary_t LDi_cond_init = LDi_cond_init_imp ;
746+ ld_cond_wait_t LDi_cond_wait = LDi_cond_wait_imp ;
747+ ld_cond_unary_t LDi_cond_signal = LDi_cond_signal_imp ;
748+ ld_cond_unary_t LDi_cond_destroy = LDi_cond_destroy_imp ;
0 commit comments