diff options
| author | Paul Dicker <pitdicker@gmail.com> | 2019-10-23 11:02:20 +0200 |
|---|---|---|
| committer | Paul Dicker <pitdicker@gmail.com> | 2019-10-24 17:28:08 +0200 |
| commit | 4b8da9ccd528d46637c88a40f6cdd0d634c0fb22 (patch) | |
| tree | 8c636455d5fc6b5856376c86764f4dcc9eaaabce /src/libstd/sync | |
| parent | 2e8eb5f33d55b507da687593bbb7042416d73058 (diff) | |
| download | rust-4b8da9ccd528d46637c88a40f6cdd0d634c0fb22.tar.gz rust-4b8da9ccd528d46637c88a40f6cdd0d634c0fb22.zip | |
Reduce the amount of comments in call_inner
Diffstat (limited to 'src/libstd/sync')
| -rw-r--r-- | src/libstd/sync/once.rs | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 2c09fb3318b..59cc6188045 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -355,25 +355,16 @@ impl Once { // performance difference really does not matter there, and // SeqCst minimizes the chances of something going wrong. let mut state_and_queue = self.state_and_queue.load(Ordering::SeqCst); - loop { match state_and_queue { - // If we're complete, then there's nothing to do, we just - // jettison out as we shouldn't run the closure. - COMPLETE => return, - - // If we're poisoned and we're not in a mode to ignore - // poisoning, then we panic here to propagate the poison. + COMPLETE => break, POISONED if !ignore_poisoning => { + // Panic to propagate the poison. panic!("Once instance has previously been poisoned"); } - - // Otherwise if we see a poisoned or otherwise incomplete state - // we will attempt to move ourselves into the RUNNING state. If - // we succeed, then the queue of waiters starts at null (all 0 - // bits). POISONED | INCOMPLETE => { + // Try to register this thread as the one RUNNING. let old = self.state_and_queue.compare_and_swap(state_and_queue, RUNNING, Ordering::SeqCst); @@ -391,15 +382,11 @@ impl Once { // poisoned or not. init(state_and_queue == POISONED); waiter_queue.set_state_on_drop_to = COMPLETE; - return + break } - - // All other values we find should correspond to the RUNNING - // state with an encoded waiter list in the more significant - // bits. We attempt to enqueue ourselves by moving us to the - // head of the list and bail out if we ever see a state that's - // not RUNNING. _ => { + // All other values must be RUNNING with possibly a + // pointer to the waiter queue in the more significant bits. assert!(state_and_queue & STATE_MASK == RUNNING); wait(&self.state_and_queue, state_and_queue); state_and_queue = self.state_and_queue.load(Ordering::SeqCst); |
