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