From df1814ba089e8b86bd7e191afa99c7bd10e05d4f Mon Sep 17 00:00:00 2001 From: James Miller Date: Sun, 26 May 2013 12:54:30 +1200 Subject: [PATCH] Add some documentation --- src/libstd/unstable/atomics.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/libstd/unstable/atomics.rs b/src/libstd/unstable/atomics.rs index fce8e003e90..ab2b5d8ea2b 100644 --- a/src/libstd/unstable/atomics.rs +++ b/src/libstd/unstable/atomics.rs @@ -10,6 +10,12 @@ /*! * Atomic types + * + * Basic atomic types supporting atomic operations. Each method takes an `Ordering` which + * represents the strength of the memory barrier for that operation. These orderings are the same + * as C++11 atomic orderings [http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync] + * + * All atomic types are a single word in size. */ use unstable::intrinsics; @@ -18,26 +24,44 @@ use option::{Option,Some,None}; use libc::c_void; use ops::Drop; +/** + * A simple atomic flag, that can be set and cleared. The most basic atomic type. + */ pub struct AtomicFlag { priv v: int } +/** + * An atomic boolean type. + */ pub struct AtomicBool { priv v: uint } +/** + * A signed atomic integer type, supporting basic atomic aritmetic operations + */ pub struct AtomicInt { priv v: int } +/** + * An unsigned atomic integer type, supporting basic atomic aritmetic operations + */ pub struct AtomicUint { priv v: uint } +/** + * An unsafe atomic pointer. Only supports basic atomic operations + */ pub struct AtomicPtr { priv p: *mut T } +/** + * An owned atomic pointer. Ensures that only a single reference to the data is held at any time. + */ pub struct AtomicOption { priv p: *mut c_void } @@ -63,11 +87,11 @@ impl AtomicFlag { unsafe {atomic_store(&mut self.v, 0, order)} } - #[inline(always)] /** * Sets the flag if it was previously unset, returns the previous value of the * flag. */ + #[inline(always)] fn test_and_set(&mut self, order: Ordering) -> bool { unsafe {atomic_compare_and_swap(&mut self.v, 0, 1, order) > 0} }