10
10
11
11
/*!
12
12
* 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.
13
19
*/
14
20
15
21
use unstable:: intrinsics;
@@ -18,26 +24,44 @@ use option::{Option,Some,None};
18
24
use libc:: c_void;
19
25
use ops:: Drop ;
20
26
27
+ /**
28
+ * A simple atomic flag, that can be set and cleared. The most basic atomic type.
29
+ */
21
30
pub struct AtomicFlag {
22
31
priv v: int
23
32
}
24
33
34
+ /**
35
+ * An atomic boolean type.
36
+ */
25
37
pub struct AtomicBool {
26
38
priv v: uint
27
39
}
28
40
41
+ /**
42
+ * A signed atomic integer type, supporting basic atomic aritmetic operations
43
+ */
29
44
pub struct AtomicInt {
30
45
priv v: int
31
46
}
32
47
48
+ /**
49
+ * An unsigned atomic integer type, supporting basic atomic aritmetic operations
50
+ */
33
51
pub struct AtomicUint {
34
52
priv v: uint
35
53
}
36
54
55
+ /**
56
+ * An unsafe atomic pointer. Only supports basic atomic operations
57
+ */
37
58
pub struct AtomicPtr < T > {
38
59
priv p: * mut T
39
60
}
40
61
62
+ /**
63
+ * An owned atomic pointer. Ensures that only a single reference to the data is held at any time.
64
+ */
41
65
pub struct AtomicOption < T > {
42
66
priv p: * mut c_void
43
67
}
@@ -63,11 +87,11 @@ impl AtomicFlag {
63
87
unsafe { atomic_store ( & mut self . v , 0 , order) }
64
88
}
65
89
66
- #[ inline( always) ]
67
90
/**
68
91
* Sets the flag if it was previously unset, returns the previous value of the
69
92
* flag.
70
93
*/
94
+ #[ inline( always) ]
71
95
fn test_and_set ( & mut self , order : Ordering ) -> bool {
72
96
unsafe { atomic_compare_and_swap ( & mut self . v , 0 , 1 , order) > 0 }
73
97
}
0 commit comments