@@ -592,6 +592,84 @@ static void os_unfair_lock_unlock(os_unfair_lock_t lock) { pthread_mutex_unlock(
592
592
#define os_unfair_lock_unlock __CFUnlock
593
593
#endif // __has_include(<os/lock.h>)
594
594
595
+ #if _POSIX_THREADS
596
+ typedef pthread_mutex_t _CFMutex ;
597
+ #define _CF_MUTEX_STATIC_INITIALIZER PTHREAD_MUTEX_INITIALIZER
598
+ static int _CFMutexCreate (_CFMutex * lock ) {
599
+ return pthread_mutex_init (lock , NULL );
600
+ }
601
+ static int _CFMutexDestroy (_CFMutex * lock ) {
602
+ return pthread_mutex_destroy (lock );
603
+ }
604
+ static int _CFMutexLock (_CFMutex * lock ) {
605
+ return pthread_mutex_lock (lock );
606
+ }
607
+ static int _CFMutexUnlock (_CFMutex * lock ) {
608
+ return pthread_mutex_unlock (lock );
609
+ }
610
+
611
+ typedef pthread_mutex_t _CFRecursiveMutex ;
612
+ static int _CFRecursiveMutexCreate (_CFRecursiveMutex * mutex ) {
613
+ pthread_mutexattr_t attr ;
614
+ pthread_mutexattr_init (& attr );
615
+ pthread_mutexattr_settype (& attr , PTHREAD_MUTEX_RECURSIVE );
616
+
617
+ int result = pthread_mutex_init (mutex , & attr );
618
+
619
+ pthread_mutexattr_destroy (& attr );
620
+
621
+ return result ;
622
+ }
623
+ static int _CFRecursiveMutexDestroy (_CFRecursiveMutex * mutex ) {
624
+ return pthread_mutex_destroy (mutex );
625
+ }
626
+ static int _CFRecursiveMutexLock (_CFRecursiveMutex * mutex ) {
627
+ return pthread_mutex_lock (mutex );
628
+ }
629
+ static int _CFRecursiveMutexUnlock (_CFRecursiveMutex * mutex ) {
630
+ return pthread_mutex_unlock (mutex );
631
+ }
632
+ #elif defined(_WIN32 )
633
+ typedef SRWLOCK _CFMutex ;
634
+ #define _CF_MUTEX_STATIC_INITIALIZER SRWLOCK_INIT
635
+ static int _CFMutexCreate (_CFMutex * lock ) {
636
+ InitializeSRWLock (lock );
637
+ return 0 ;
638
+ }
639
+ static int _CFMutexDestroy (_CFMutex * lock ) {
640
+ (void )lock ;
641
+ return 0 ;
642
+ }
643
+ static int _CFMutexLock (_CFMutex * lock ) {
644
+ AcquireSRWLockExclusive (lock );
645
+ return 0 ;
646
+ }
647
+ static int _CFMutexUnlock (_CFMutex * lock ) {
648
+ ReleaseSRWLockExclusive (lock );
649
+ return 0 ;
650
+ }
651
+
652
+ typedef CRITICAL_SECTION _CFRecursiveMutex ;
653
+ static int _CFRecursiveMutexCreate (_CFRecursiveMutex * mutex ) {
654
+ InitializeCriticalSection (mutex );
655
+ return 0 ;
656
+ }
657
+ static int _CFRecursiveMutexDestroy (_CFRecursiveMutex * mutex ) {
658
+ DeleteCriticalSection (mutex );
659
+ return 0 ;
660
+ }
661
+ static int _CFRecursiveMutexLock (_CFRecursiveMutex * mutex ) {
662
+ EnterCriticalSection (mutex );
663
+ return 0 ;
664
+ }
665
+ static int _CFRecursiveMutexUnlock (_CFRecursiveMutex * mutex ) {
666
+ LeaveCriticalSection (mutex );
667
+ return 0 ;
668
+ }
669
+ #else
670
+ #error "do not know how to define mutex and recursive mutex for this OS"
671
+ #endif
672
+
595
673
#if !__HAS_DISPATCH__
596
674
597
675
typedef volatile long dispatch_once_t ;
0 commit comments