39
39
use std:: {
40
40
alloc:: Layout ,
41
41
fmt:: Debug ,
42
- sync:: atomic:: { AtomicBool , AtomicU8 , Ordering } ,
42
+ sync:: atomic:: { AtomicBool , AtomicIsize , AtomicU8 , AtomicUsize , Ordering } ,
43
43
} ;
44
44
45
45
use iceoryx2_bb_elementary:: {
@@ -59,7 +59,6 @@ pub type RelocatableBitSet = details::BitSet<RelocatablePointer<details::BitsetE
59
59
60
60
#[ doc( hidden) ]
61
61
pub mod details {
62
- use std:: sync:: atomic:: AtomicUsize ;
63
62
64
63
use super :: * ;
65
64
@@ -87,7 +86,7 @@ pub mod details {
87
86
capacity : usize ,
88
87
array_capacity : usize ,
89
88
reset_position : AtomicUsize ,
90
- active_bits : AtomicUsize ,
89
+ active_bits : AtomicIsize ,
91
90
is_memory_initialized : AtomicBool ,
92
91
}
93
92
@@ -115,7 +114,7 @@ pub mod details {
115
114
array_capacity,
116
115
is_memory_initialized : AtomicBool :: new ( true ) ,
117
116
reset_position : AtomicUsize :: new ( 0 ) ,
118
- active_bits : AtomicUsize :: new ( 0 ) ,
117
+ active_bits : AtomicIsize :: new ( 0 ) ,
119
118
}
120
119
}
121
120
}
@@ -128,7 +127,7 @@ pub mod details {
128
127
array_capacity : Self :: array_capacity ( capacity) ,
129
128
is_memory_initialized : AtomicBool :: new ( false ) ,
130
129
reset_position : AtomicUsize :: new ( 0 ) ,
131
- active_bits : AtomicUsize :: new ( 0 ) ,
130
+ active_bits : AtomicIsize :: new ( 0 ) ,
132
131
}
133
132
}
134
133
@@ -176,7 +175,7 @@ pub mod details {
176
175
array_capacity : Self :: array_capacity ( capacity) ,
177
176
is_memory_initialized : AtomicBool :: new ( true ) ,
178
177
reset_position : AtomicUsize :: new ( 0 ) ,
179
- active_bits : AtomicUsize :: new ( 0 ) ,
178
+ active_bits : AtomicIsize :: new ( 0 ) ,
180
179
}
181
180
}
182
181
}
@@ -277,14 +276,17 @@ pub mod details {
277
276
/// [`None`].
278
277
pub fn reset_next ( & self ) -> Option < usize > {
279
278
self . verify_init ( "reset_next" ) ;
280
- if self . active_bits . load ( Ordering :: Relaxed ) == 0 {
279
+ let active_bits = self . active_bits . load ( Ordering :: Relaxed ) ;
280
+ if active_bits <= 0 {
281
281
return None ;
282
282
}
283
283
284
284
let current_position = self . reset_position . load ( Ordering :: Relaxed ) ;
285
285
for pos in ( current_position..self . capacity ) . chain ( 0 ..current_position) {
286
286
if self . clear_bit ( Id :: new ( pos) ) {
287
- self . reset_position . store ( pos + 1 , Ordering :: Relaxed ) ;
287
+ if active_bits != 1 {
288
+ self . reset_position . store ( pos + 1 , Ordering :: Relaxed ) ;
289
+ }
288
290
return Some ( pos) ;
289
291
}
290
292
}
@@ -308,7 +310,7 @@ pub mod details {
308
310
}
309
311
}
310
312
311
- if self . active_bits . fetch_sub ( counter, Ordering :: Relaxed ) = = counter {
313
+ if self . active_bits . fetch_sub ( counter, Ordering :: Relaxed ) < = counter {
312
314
return ;
313
315
}
314
316
}
0 commit comments