     /// - returns: The value returned from the given function.
     public func withReadLock<Return>(@noescape body: () throws -> Return) rethrows -> Return {
         OSSpinLockLock(lock)
+        defer {
+            OSSpinLockUnlock(lock)
+        }
+        return try body()
+    }
+
+    /// Attempt to call `body` with a lock.
+    /// - returns: The value returned from `body`, or `nil` if already locked.
+    /// - seealso: withReadLock(_:)
+    public func withAttemptedReadLock<Return>(@noescape body: () throws -> Return) rethrows -> Return? {
+        guard OSSpinLockTry(lock) else { return nil }
         defer {
             OSSpinLockUnlock(lock)
         }

    /// Create a normal instance.
    public init() {}

    /// Call `body` with a lock.
    /// - parameter body: A function that reads a value while locked.
    /// - returns: The value returned from the given function.
    public func withReadLock<Return>(@noescape body: () throws -> Return) rethrows -> Return {
        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER)
        defer {
            dispatch_semaphore_signal(semaphore)
        }
        return try body()
    }
}



        return try body()
    }

    /// Attempt to call `body` with a lock.
    ///
    /// `body` may be called concurrently with reads on other threads.
    ///
    /// - returns: The value returned from `body`, or `nil` if already locked.
    /// - seealso: withReadLock(_:)
    public func withAttemptedReadLock<Return>(@noescape body: () throws -> Return) rethrows -> Return? {
        // active writer
        guard (state.memory & Constants.WriterMask) == 0 else { return nil }

        // increment the reader count
        guard (OSAtomicIncrement32Barrier(state) & Constants.WriterMask) == 0 else { return nil }

        defer {
            // decrement readers, potentially unblock writers
            OSAtomicDecrement32Barrier(state)
        }

        return try body()
    }
}

/// A readers-writer lock provided by the platform implementation of the
