Created
August 21, 2014 16:58
-
-
Save macu/3843eec563e74a5e5804 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AtomicBoolean { | |
| private var val: Byte = 0 | |
| /// Sets the value, and returns the previous value. | |
| /// The test/set is an atomic operation. | |
| func testAndSet(value: Bool) -> Bool { | |
| if value { | |
| return OSAtomicTestAndSet(0, &val) | |
| } else { | |
| return OSAtomicTestAndClear(0, &val) | |
| } | |
| } | |
| /// Returns the current value of the boolean. | |
| /// The value may change before this method returns. | |
| func test() -> Bool { | |
| return val != 0 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment