Created
January 30, 2015 20:14
-
-
Save a2/586a5d5cb4dcae6bfcc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Mutex { | |
private let _mutex = UnsafeMutablePointer<pthread_mutex_t>.alloc(1) | |
init() { | |
pthread_mutex_init(_mutex, nil) | |
} | |
func lock() -> Int32 { | |
return pthread_mutex_lock(_mutex) | |
} | |
func unlock() -> Int32 { | |
return pthread_mutex_unlock(_mutex) | |
} | |
func tryLock() -> Int32 { | |
return pthread_mutex_trylock(_mutex) | |
} | |
deinit { | |
pthread_mutex_destroy(_mutex) | |
_mutex.dealloc(1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment