         } while true
 
         // write lock acquired - run block
-        let result = block()
+        let result = body()
 
         // unlock
         do {

        lock.dealloc(1)
    }

    public func withReadLock<T>(block: () -> T) -> T {
        OSSpinLockLock(lock)
        let result = block()
        OSSpinLockUnlock(lock)
        return result
    }

    public func withWriteLock<T>(block: () -> T) -> T {
        OSSpinLockLock(lock)
        let result = block()
        OSSpinLockUnlock(lock)
        return result
    }
}



    public init() {}

    private func withLock<T>(@noescape body: () -> T) -> T {
        let result: T
        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER)
        result = body()
        dispatch_semaphore_signal(semaphore)
        return result
    }

    public func withReadLock<T>(@noescape body: () -> T) -> T {
        return withLock(body)
    }

    public func withWriteLock<T>(@noescape body: () -> T) -> T {
        return withLock(body)
    }
}

