     
     @discardableResult
     public func synchronized<R>(for predicate: @autoclosure () -> Bool, block: () throws -> R) rethrows -> R {
-        self.lock(for: predicate)
-        defer { self.unlock() }
-        return try block()
+        return try self.synchronized(cond, for: predicate, block: block)
     }
     @discardableResult
     public func synchronized<R>(for predicate: @autoclosure () -> Bool, until date: Date, block: () throws -> R) rethrows -> R? {
-        if self.lock(for: predicate, until: date) {
-            defer { self.unlock() }
-            return try block()
-        }
-        return nil
+        return try self.synchronized(cond, for: predicate, until: date, block: block)
     }
 }
 

    }
}

// MARK: Spin Lock

public class SDSpinLock {


public class SDConditionLock : SDLock {
    
    fileprivate var cond = SDCondition()
}

extension SDConditionLock {
    
    public func signal() {
        super.synchronized {
            cond.signal()
        }
    }
    public func broadcast() {
        super.synchronized {
            cond.broadcast()
        }
    }
    public func wait(for predicate: @autoclosure () -> Bool) {
        self.wait(cond, for: predicate)
    }
    @discardableResult
    public func wait(for predicate: @autoclosure () -> Bool, until date: Date) -> Bool {
        return self.wait(cond, for: predicate, until: date)
    }
}

extension SDConditionLock {
    
    public func lock(for predicate: @autoclosure () -> Bool) {
        self.lock(cond, for: predicate)
    }
    @discardableResult
    public func lock(for predicate: @autoclosure () -> Bool, until date: Date) -> Bool {
        return self.lock(cond, for: predicate, until: date)
    }
    @discardableResult
    public func trylock(for predicate: @autoclosure () -> Bool) -> Bool {
        return self.trylock(cond, for: predicate)
    }
}

