@@ -15,15 +15,15 @@ use core::sync::atomic::Ordering::{Acquire, Release};
15
15
/// notify the consumer, but the consumer is in the process of being migrated to
16
16
/// a new logical task.
17
17
///
18
- /// Roughly, consumers should call `park ` before checking the result of a
19
- /// computation and producers should call `notify` after producing the
20
- /// computation . It is also permitted for `notify` to be called **before**
21
- /// `park `. This results in a no-op.
18
+ /// Consumers should call `register ` before checking the result of a computation
19
+ /// and producers should call `notify` after producing the computation (this
20
+ /// differs from the usual `thread::park` pattern) . It is also permitted for
21
+ /// `notify` to be called **before** `register `. This results in a no-op.
22
22
///
23
- /// A single `AtomicTask` may be reused for any number of calls to `park ` or
24
- /// `noitfy `.
23
+ /// A single `AtomicTask` may be reused for any number of calls to `register ` or
24
+ /// `notify `.
25
25
///
26
- /// `AtomicTask` does not provide any guaranteed memory ordering, as such the
26
+ /// `AtomicTask` does not provide any memory ordering guarantees , as such the
27
27
/// user should use caution and use other synchronization primitives to guard
28
28
/// the result of the underlying computation.
29
29
pub struct AtomicTask {
@@ -39,15 +39,16 @@ pub struct AtomicTask {
39
39
/// a lock.
40
40
const WAITING : usize = 2 ;
41
41
42
- /// The `park ` function has determined that the task is no longer current. This
43
- /// implies that `AtomicTask::park ` is being called from a different task than
44
- /// is represented by the currently stored task. The write lock is obtained to
45
- /// update the task cell.
42
+ /// The `register ` function has determined that the task is no longer current.
43
+ /// This implies that `AtomicTask::register ` is being called from a different
44
+ /// task than is represented by the currently stored task. The write lock is
45
+ /// obtained to update the task cell.
46
46
const LOCKED_WRITE : usize = 0 ;
47
47
48
- /// At least one call to `notify` happened concurrently to `park` updating the
49
- /// task cell. This state is detected when `park` exits the mutation code and
50
- /// signals to `park` that it is responsible for notifying its own task.
48
+ /// At least one call to `notify` happened concurrently to `register` updating
49
+ /// the task cell. This state is detected when `register` exits the mutation
50
+ /// code and signals to `register` that it is responsible for notifying its own
51
+ /// task.
51
52
const LOCKED_WRITE_NOTIFIED : usize = 1 ;
52
53
53
54
@@ -70,22 +71,22 @@ impl AtomicTask {
70
71
}
71
72
}
72
73
73
- /// Sets the current task to be notified on calls to `notify`.
74
+ /// Registers the current task to be notified on calls to `notify`.
74
75
///
75
76
/// The new task will take place of any previous tasks that were registered
76
- /// by previous calls to `park `. Any calls to `notify` that happen after
77
- /// a call to `park ` (as defined by the memory ordering rules), will notify
78
- /// the `park ` caller's task.
77
+ /// by previous calls to `register `. Any calls to `notify` that happen after
78
+ /// a call to `register ` (as defined by the memory ordering rules), will
79
+ /// notify the `register ` caller's task.
79
80
///
80
- /// It is safe to call `park ` with multiple other threads concurrently
81
- /// calling `notify`. This will result in the `park ` caller's current task
82
- /// being notified once.
81
+ /// It is safe to call `register ` with multiple other threads concurrently
82
+ /// calling `notify`. This will result in the `register ` caller's current
83
+ /// task being notified once.
83
84
///
84
85
/// This function is safe to call concurrently, but this is generally a bad
85
- /// idea. Concurrent calls to `park ` will attempt to register different
86
+ /// idea. Concurrent calls to `register ` will attempt to register different
86
87
/// tasks to be notified. One of the callers will win and have its task set,
87
88
/// but there is no guarantee as to which caller will succeed.
88
- pub fn park ( & self ) {
89
+ pub fn register ( & self ) {
89
90
// Get a new task handle
90
91
let task = super :: current ( ) ;
91
92
@@ -104,7 +105,7 @@ impl AtomicTask {
104
105
}
105
106
}
106
107
LOCKED_WRITE | LOCKED_WRITE_NOTIFIED => {
107
- // A thread is concurrently calling `park `. This shouldn't
108
+ // A thread is concurrently calling `register `. This shouldn't
108
109
// happen as it doesn't really make much sense, but it isn't
109
110
// unsafe per se. Since two threads are concurrently trying to
110
111
// update the task, it's undefined which one "wins" (no ordering
@@ -122,9 +123,9 @@ impl AtomicTask {
122
123
}
123
124
}
124
125
125
- /// Notifies the task that last called `park `.
126
+ /// Notifies the task that last called `register `.
126
127
///
127
- /// If `park ` has not been called yet, then this does nothing.
128
+ /// If `register ` has not been called yet, then this does nothing.
128
129
pub fn notify ( & self ) {
129
130
let mut curr = WAITING ;
130
131
0 commit comments