File tree Expand file tree Collapse file tree 1 file changed +17
-9
lines changed
Sources/CombineSchedulers/Internal Expand file tree Collapse file tree 1 file changed +17
-9
lines changed Original file line number Diff line number Diff line change 4343 }
4444 }
4545#else
46+ import pthread
4647struct Lock {
48+ private let lockPtr : UnsafeMutablePointer < pthread_mutex_t >
49+
4750 internal init ( ) {
48-
51+ lockPtr = UnsafeMutablePointer< pthread_mutex_t> . allocate( capacity: 1 )
52+ var attr = pthread_mutexattr_t ( )
53+ pthread_mutexattr_settype ( & attr, Int32 ( PTHREAD_MUTEX_RECURSIVE) )
54+ pthread_mutex_init ( lockPtr, & attr)
4955 }
50-
56+
5157 internal func cleanupLock( ) {
52-
58+ pthread_mutex_destroy ( lockPtr)
59+ lockPtr. deinitialize ( count: 1 )
60+ lockPtr. deallocate ( )
5361 }
54-
62+
5563 internal func lock( ) {
56-
64+ pthread_mutex_lock ( lockPtr )
5765 }
58-
66+
5967 internal func tryLock( ) -> Bool {
60- return false
68+ return pthread_mutex_trylock ( lockPtr ) == 0
6169 }
62-
70+
6371 internal func unlock( ) {
64-
72+ pthread_mutex_unlock ( lockPtr )
6573 }
6674}
6775#endif
You can’t perform that action at this time.
0 commit comments