Skip to content

Commit c727e17

Browse files
committed
Rename AtomicTask::park -> register
1 parent 231b56b commit c727e17

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed

src/stream/futures_unordered.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,8 @@ impl<T> Stream for FuturesUnordered<T>
279279
type Error = T::Error;
280280

281281
fn poll(&mut self) -> Poll<Option<T::Item>, T::Error> {
282-
// Ensure `parent` is correctly set. Note that the `unsafe` here is
283-
// because the `park` method underneath needs mutual exclusion from
284-
// other calls to `park`, which we guarantee with `&mut self` above and
285-
// this is the only method which calls park.
286-
self.inner.parent.park();
282+
// Ensure `parent` is correctly set.
283+
self.inner.parent.register();
287284

288285
loop {
289286
let node = match unsafe { self.inner.dequeue() } {

src/task_impl/atomic_task.rs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ use core::sync::atomic::Ordering::{Acquire, Release};
1515
/// notify the consumer, but the consumer is in the process of being migrated to
1616
/// a new logical task.
1717
///
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.
2222
///
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`.
2525
///
26-
/// `AtomicTask` does not provide any guaranteed memory ordering, as such the
26+
/// `AtomicTask` does not provide any memory ordering guarantees, as such the
2727
/// user should use caution and use other synchronization primitives to guard
2828
/// the result of the underlying computation.
2929
pub struct AtomicTask {
@@ -39,15 +39,16 @@ pub struct AtomicTask {
3939
/// a lock.
4040
const WAITING: usize = 2;
4141

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.
4646
const LOCKED_WRITE: usize = 0;
4747

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.
5152
const LOCKED_WRITE_NOTIFIED: usize = 1;
5253

5354

@@ -70,22 +71,22 @@ impl AtomicTask {
7071
}
7172
}
7273

73-
/// Sets the current task to be notified on calls to `notify`.
74+
/// Registers the current task to be notified on calls to `notify`.
7475
///
7576
/// 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.
7980
///
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.
8384
///
8485
/// 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
8687
/// tasks to be notified. One of the callers will win and have its task set,
8788
/// but there is no guarantee as to which caller will succeed.
88-
pub fn park(&self) {
89+
pub fn register(&self) {
8990
// Get a new task handle
9091
let task = super::current();
9192

@@ -104,7 +105,7 @@ impl AtomicTask {
104105
}
105106
}
106107
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
108109
// happen as it doesn't really make much sense, but it isn't
109110
// unsafe per se. Since two threads are concurrently trying to
110111
// update the task, it's undefined which one "wins" (no ordering
@@ -122,9 +123,9 @@ impl AtomicTask {
122123
}
123124
}
124125

125-
/// Notifies the task that last called `park`.
126+
/// Notifies the task that last called `register`.
126127
///
127-
/// If `park` has not been called yet, then this does nothing.
128+
/// If `register` has not been called yet, then this does nothing.
128129
pub fn notify(&self) {
129130
let mut curr = WAITING;
130131

0 commit comments

Comments
 (0)