Skip to content

Commit df1814b

Browse files
author
James Miller
committed
Add some documentation
1 parent 30b471b commit df1814b

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/libstd/unstable/atomics.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111
/*!
1212
* Atomic types
13+
*
14+
* Basic atomic types supporting atomic operations. Each method takes an `Ordering` which
15+
* represents the strength of the memory barrier for that operation. These orderings are the same
16+
* as C++11 atomic orderings [http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync]
17+
*
18+
* All atomic types are a single word in size.
1319
*/
1420

1521
use unstable::intrinsics;
@@ -18,26 +24,44 @@ use option::{Option,Some,None};
1824
use libc::c_void;
1925
use ops::Drop;
2026

27+
/**
28+
* A simple atomic flag, that can be set and cleared. The most basic atomic type.
29+
*/
2130
pub struct AtomicFlag {
2231
priv v: int
2332
}
2433

34+
/**
35+
* An atomic boolean type.
36+
*/
2537
pub struct AtomicBool {
2638
priv v: uint
2739
}
2840

41+
/**
42+
* A signed atomic integer type, supporting basic atomic aritmetic operations
43+
*/
2944
pub struct AtomicInt {
3045
priv v: int
3146
}
3247

48+
/**
49+
* An unsigned atomic integer type, supporting basic atomic aritmetic operations
50+
*/
3351
pub struct AtomicUint {
3452
priv v: uint
3553
}
3654

55+
/**
56+
* An unsafe atomic pointer. Only supports basic atomic operations
57+
*/
3758
pub struct AtomicPtr<T> {
3859
priv p: *mut T
3960
}
4061

62+
/**
63+
* An owned atomic pointer. Ensures that only a single reference to the data is held at any time.
64+
*/
4165
pub struct AtomicOption<T> {
4266
priv p: *mut c_void
4367
}
@@ -63,11 +87,11 @@ impl AtomicFlag {
6387
unsafe {atomic_store(&mut self.v, 0, order)}
6488
}
6589

66-
#[inline(always)]
6790
/**
6891
* Sets the flag if it was previously unset, returns the previous value of the
6992
* flag.
7093
*/
94+
#[inline(always)]
7195
fn test_and_set(&mut self, order: Ordering) -> bool {
7296
unsafe {atomic_compare_and_swap(&mut self.v, 0, 1, order) > 0}
7397
}

0 commit comments

Comments
 (0)