         pthread_mutex_destroy(&mutex)
     }
 
-    func sync(@noescape closure: () -> Void) {
-        let status = pthread_mutex_lock(&mutex)
+    func lock() -> Int32 {
+        return pthread_mutex_lock(&mutex)
+    }
+
+    func unlock() -> Int32 {
+        return pthread_mutex_unlock(&mutex)
+    }
+
+    func lock(@noescape closure: () -> Void) {
+        let status = lock()
         assert(status == 0, "pthread_mutex_lock: \(strerror(status))")
-        defer { pthread_mutex_unlock(&mutex) }
+        defer { unlock() }
         closure()
     }
 }

}


private class Lock {
    private var mutex = pthread_mutex_t()

    init() {

        if let value = value {
            f(value)
        }
        mutex.lock {
            callbacks.append(f)
        }
        return self
