@@ -190,24 +190,14 @@ impl State {
190
190
///
191
191
/// Returns true if the task should be deallocated.
192
192
pub ( super ) fn transition_to_terminal ( & self , count : usize ) -> bool {
193
- self . fetch_update_action ( |mut snapshot| {
194
- assert ! (
195
- snapshot. ref_count( ) >= count,
196
- "current: {}, sub: {}" ,
197
- snapshot. ref_count( ) ,
198
- count
199
- ) ;
200
-
201
- snapshot. 0 -= count * REF_ONE ;
202
- if snapshot. is_join_interested ( ) {
203
- // If there is still a join handle alive at this point we unset the
204
- // JOIN_WAKER bit so that the join handle gains exclusive access to
205
- // the waker field to actually drop it.
206
- snapshot. unset_join_waker ( ) ;
207
- }
208
-
209
- ( snapshot. ref_count ( ) == 0 , Some ( snapshot) )
210
- } )
193
+ let prev = Snapshot ( self . val . fetch_sub ( count * REF_ONE , AcqRel ) ) ;
194
+ assert ! (
195
+ prev. ref_count( ) >= count,
196
+ "current: {}, sub: {}" ,
197
+ prev. ref_count( ) ,
198
+ count
199
+ ) ;
200
+ prev. ref_count ( ) == count
211
201
}
212
202
213
203
/// Transitions the state to `NOTIFIED`.
@@ -389,13 +379,20 @@ impl State {
389
379
self . fetch_update ( |curr| {
390
380
assert ! ( curr. is_join_interested( ) ) ;
391
381
392
- if curr. is_complete ( ) {
393
- return None ;
394
- }
382
+ // if curr.is_complete() {
383
+ // return None;
384
+ // }
385
+
386
+ // let mut next = curr;
387
+ // next.unset_join_interested();
388
+
389
+ // Some(next)
395
390
396
391
let mut next = curr;
397
392
next. unset_join_interested ( ) ;
398
-
393
+ if !curr. is_complete ( ) {
394
+ next. unset_join_waker ( ) ;
395
+ }
399
396
Some ( next)
400
397
} )
401
398
}
@@ -440,6 +437,26 @@ impl State {
440
437
} )
441
438
}
442
439
440
+ /// Unsets the `JOIN_WAKER` bit only if the `JOIN_INTEREST` is still set.
441
+ ///
442
+ /// Returns `Ok` has been unset, `Err` otherwise. This operation requires
443
+ /// the task to be completed.
444
+ pub ( super ) fn unset_waker_if_join_interested ( & self ) -> UpdateResult {
445
+ self . fetch_update ( |curr| {
446
+ assert ! ( curr. is_complete( ) ) ;
447
+ assert ! ( curr. is_join_waker_set( ) ) ;
448
+
449
+ if !curr. is_join_interested ( ) {
450
+ return None ;
451
+ }
452
+
453
+ let mut next = curr;
454
+ next. unset_join_waker ( ) ;
455
+
456
+ Some ( next)
457
+ } )
458
+ }
459
+
443
460
pub ( super ) fn ref_inc ( & self ) {
444
461
use std:: process;
445
462
use std:: sync:: atomic:: Ordering :: Relaxed ;
0 commit comments