File tree Expand file tree Collapse file tree 1 file changed +11
-27
lines changed Expand file tree Collapse file tree 1 file changed +11
-27
lines changed Original file line number Diff line number Diff line change @@ -103,38 +103,22 @@ impl<T> QueueCore<T> {
103
103
///
104
104
/// It can be marked as sleep only when the pool is not shutting down.
105
105
pub fn mark_sleep ( & self ) -> bool {
106
- let mut cnt = self . active_workers . load ( Ordering :: SeqCst ) ;
107
- loop {
108
- if is_shutdown ( cnt) {
109
- return false ;
110
- }
111
-
112
- match self . active_workers . compare_exchange_weak (
113
- cnt,
114
- cnt - WORKER_COUNT_BASE ,
115
- Ordering :: SeqCst ,
116
- Ordering :: SeqCst ,
117
- ) {
118
- Ok ( _) => return true ,
119
- Err ( n) => cnt = n,
120
- }
106
+ let shutdown = is_shutdown (
107
+ self . active_workers
108
+ . fetch_sub ( WORKER_COUNT_BASE , Ordering :: SeqCst ) ,
109
+ ) ;
110
+ if shutdown {
111
+ // keep the right number here though it is not used anymore
112
+ self . active_workers
113
+ . fetch_add ( WORKER_COUNT_BASE , Ordering :: SeqCst ) ;
121
114
}
115
+ !shutdown
122
116
}
123
117
124
118
/// Marks current thread as woken up states.
125
119
pub fn mark_woken ( & self ) {
126
- let mut cnt = self . active_workers . load ( Ordering :: SeqCst ) ;
127
- loop {
128
- match self . active_workers . compare_exchange_weak (
129
- cnt,
130
- cnt + WORKER_COUNT_BASE ,
131
- Ordering :: SeqCst ,
132
- Ordering :: SeqCst ,
133
- ) {
134
- Ok ( _) => return ,
135
- Err ( n) => cnt = n,
136
- }
137
- }
120
+ self . active_workers
121
+ . fetch_add ( WORKER_COUNT_BASE , Ordering :: SeqCst ) ;
138
122
}
139
123
140
124
/// Scale workers.
You can’t perform that action at this time.
0 commit comments