File tree 3 files changed +14
-3
lines changed
3 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ required-features = ["barging"]
51
51
52
52
[[example ]]
53
53
name = " parking"
54
- required-features = [" parking" ]
54
+ required-features = [" parking" , " thread_local " ]
55
55
56
56
[[example ]]
57
57
name = " thread_local"
Original file line number Diff line number Diff line change @@ -6,6 +6,15 @@ use std::thread;
6
6
// `spins::Mutex` spins for a while then parks during contention.
7
7
use mcslock:: parking:: raw:: { spins:: Mutex , MutexNode } ;
8
8
9
+ // Requires that the `thread_local` feature is enabled.
10
+ mcslock:: thread_local_parking_node! {
11
+ // * Allows multiple static definitions, must be separated with semicolons.
12
+ // * Visibility is optional (private by default).
13
+ // * Requires `static` keyword and a UPPER_SNAKE_CASE name.
14
+ pub static NODE ;
15
+ static UNUSED_NODE ;
16
+ }
17
+
9
18
fn main ( ) {
10
19
const N : usize = 10 ;
11
20
@@ -41,7 +50,7 @@ fn main() {
41
50
}
42
51
let _message = rx. recv ( ) ;
43
52
44
- // A queue node is transparently allocated in the stack .
45
- let count = data. lock_then ( |data| * data) ;
53
+ // A thread local node is borrowed .
54
+ let count = data. lock_with_local_then ( & NODE , |data| * data) ;
46
55
assert_eq ! ( count, N ) ;
47
56
}
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ fn main() {
35
35
// threads to ever fail while holding the lock.
36
36
//
37
37
// Data is exclusively accessed by the guard argument.
38
+ // A thread local node is borrowed.
38
39
data. lock_with_local_then ( & NODE , |data| {
39
40
* data += 1 ;
40
41
if * data == N {
@@ -46,6 +47,7 @@ fn main() {
46
47
}
47
48
let _message = rx. recv ( ) ;
48
49
50
+ // A thread local node is borrowed.
49
51
let count = data. lock_with_local_then ( & NODE , |data| * data) ;
50
52
assert_eq ! ( count, N ) ;
51
53
}
You can’t perform that action at this time.
0 commit comments