Created
December 2, 2014 01:58
-
-
Save reem/89434a762b9b8b98944f 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
pub fn lock(&self) -> Option<OnceMutexGuard<T>> { | |
match state.load(SeqCst) { | |
UNUSED => { | |
state.store(LOCKED, SeqCst); | |
Some(OnceMutexGuard::new(self)) | |
}, | |
// Other thread got here first or already locked. | |
// Either way, no lock. | |
_ => None | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment