1
1
use std:: ptr:: NonNull ;
2
2
3
- use crossbeam_queue:: SegQueue ;
4
-
5
3
use super :: memo:: Memo ;
6
4
use super :: Configuration ;
7
5
8
6
/// Stores the list of memos that have been deleted so they can be freed
9
7
/// once the next revision starts. See the comment on the field
10
8
/// `deleted_entries` of [`FunctionIngredient`][] for more details.
11
9
pub ( super ) struct DeletedEntries < C : Configuration > {
12
- seg_queue : SegQueue < SharedBox < Memo < C :: Output < ' static > > > > ,
10
+ memos : boxcar :: Vec < SharedBox < Memo < C :: Output < ' static > > > > ,
13
11
}
14
12
15
13
unsafe impl < T : Send > Send for SharedBox < T > { }
@@ -18,30 +16,32 @@ unsafe impl<T: Sync> Sync for SharedBox<T> {}
18
16
impl < C : Configuration > Default for DeletedEntries < C > {
19
17
fn default ( ) -> Self {
20
18
Self {
21
- seg_queue : Default :: default ( ) ,
19
+ memos : Default :: default ( ) ,
22
20
}
23
21
}
24
22
}
25
23
26
24
impl < C : Configuration > DeletedEntries < C > {
27
25
/// # Safety
28
26
///
29
- /// The memo must be valid and safe to free when the `DeletedEntries` list is dropped.
27
+ /// The memo must be valid and safe to free when the `DeletedEntries` list is cleared or dropped.
30
28
pub ( super ) unsafe fn push ( & self , memo : NonNull < Memo < C :: Output < ' _ > > > ) {
31
29
let memo = unsafe {
32
30
std:: mem:: transmute :: < NonNull < Memo < C :: Output < ' _ > > > , NonNull < Memo < C :: Output < ' static > > > > (
33
31
memo,
34
32
)
35
33
} ;
36
34
37
- self . seg_queue . push ( SharedBox ( memo) ) ;
35
+ self . memos . push ( SharedBox ( memo) ) ;
36
+ }
37
+
38
+ /// Free all deleted memos, keeping the list available for reuse.
39
+ pub ( super ) fn clear ( & mut self ) {
40
+ self . memos . clear ( ) ;
38
41
}
39
42
}
40
43
41
44
/// A wrapper around `NonNull` that frees the allocation when it is dropped.
42
- ///
43
- /// `crossbeam::SegQueue` does not expose mutable accessors so we have to create
44
- /// a wrapper to run code during `Drop`.
45
45
struct SharedBox < T > ( NonNull < T > ) ;
46
46
47
47
impl < T > Drop for SharedBox < T > {
0 commit comments