Merge pull request #225 from beerpiss/mutex-to-dispatchsemaphore

Add Windows support
This commit is contained in:
Nabil Chatbi 2022-07-22 13:14:58 +02:00 committed by GitHub
commit a482e88dfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 1 deletions

View File

@ -8,8 +8,30 @@
import Foundation
#if os(Windows)
import WinSDK
#endif
final class Mutex: NSLocking {
#if os(Windows)
private var mutex = CRITICAL_SECTION()
init() {
InitializeCriticalSection(&mutex)
}
deinit {
DeleteCriticalSection(&mutex)
}
func lock() {
EnterCriticalSection(&mutex)
}
func unlock() {
LeaveCriticalSection(&mutex)
}
#else
private var mutex = pthread_mutex_t()
init() {
@ -27,4 +49,5 @@ final class Mutex: NSLocking {
func unlock() {
pthread_mutex_unlock(&mutex)
}
#endif
}