     }
 }
 
+extension NSRecursiveLock {
+    func withCriticalScope<T>(@noescape block: () -> T) -> T {
+        lock()
+        let value = block()
+        unlock()
+        return value
+    }
+}
+
+

    }

    private let stateLock = NSLock()

    private var _state = State.Initialized
    private var _internalErrors = [ErrorType]()


    /// Boolean indicator of the readyness of the Operation
    public override var ready: Bool {
        return readyLock.withCriticalScope {
            switch state {
            case .Initialized:
                // If the operation is cancelled, isReady should return true
                return cancelled

            case .Pending:
                // If the operation is cancelled, isReady should return true
                if cancelled {
                    state = .Ready
                    return true
                }

                if super.ready {
                    return evaluateConditions()
                }

                // Until conditions have been evaluated, we're not ready
                return false

            case .Ready:
                return super.ready || cancelled

            default:
                return false
            }
        }
    }

