@@ -355,25 +355,16 @@ impl Once {
355
355
// performance difference really does not matter there, and
356
356
// SeqCst minimizes the chances of something going wrong.
357
357
let mut state_and_queue = self . state_and_queue . load ( Ordering :: SeqCst ) ;
358
-
359
358
loop {
360
359
match state_and_queue {
361
- // If we're complete, then there's nothing to do, we just
362
- // jettison out as we shouldn't run the closure.
363
- COMPLETE => return ,
364
-
365
- // If we're poisoned and we're not in a mode to ignore
366
- // poisoning, then we panic here to propagate the poison.
360
+ COMPLETE => break ,
367
361
POISONED if !ignore_poisoning => {
362
+ // Panic to propagate the poison.
368
363
panic ! ( "Once instance has previously been poisoned" ) ;
369
364
}
370
-
371
- // Otherwise if we see a poisoned or otherwise incomplete state
372
- // we will attempt to move ourselves into the RUNNING state. If
373
- // we succeed, then the queue of waiters starts at null (all 0
374
- // bits).
375
365
POISONED |
376
366
INCOMPLETE => {
367
+ // Try to register this thread as the one RUNNING.
377
368
let old = self . state_and_queue . compare_and_swap ( state_and_queue,
378
369
RUNNING ,
379
370
Ordering :: SeqCst ) ;
@@ -391,15 +382,11 @@ impl Once {
391
382
// poisoned or not.
392
383
init ( state_and_queue == POISONED ) ;
393
384
waiter_queue. set_state_on_drop_to = COMPLETE ;
394
- return
385
+ break
395
386
}
396
-
397
- // All other values we find should correspond to the RUNNING
398
- // state with an encoded waiter list in the more significant
399
- // bits. We attempt to enqueue ourselves by moving us to the
400
- // head of the list and bail out if we ever see a state that's
401
- // not RUNNING.
402
387
_ => {
388
+ // All other values must be RUNNING with possibly a
389
+ // pointer to the waiter queue in the more significant bits.
403
390
assert ! ( state_and_queue & STATE_MASK == RUNNING ) ;
404
391
wait ( & self . state_and_queue , state_and_queue) ;
405
392
state_and_queue = self . state_and_queue . load ( Ordering :: SeqCst ) ;
0 commit comments