Skip to content

Instantly share code, notes, and snippets.

@a2
Created January 30, 2015 20:14
Show Gist options
  • Save a2/586a5d5cb4dcae6bfcc4 to your computer and use it in GitHub Desktop.
Save a2/586a5d5cb4dcae6bfcc4 to your computer and use it in GitHub Desktop.
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