1
- use std:: sync:: { Arc } ;
2
1
use std:: cell:: { Cell , UnsafeCell } ;
3
2
use std:: sync:: atomic:: { Ordering , AtomicBool } ;
4
3
5
4
use slog:: { Logger , FnValue , trace, Drain , o} ;
6
5
7
- use crate :: { RawSimpleCollector } ;
6
+ use crate :: { RawSimpleCollector , SimpleCollector } ;
8
7
use crate :: utils:: ThreadId ;
9
8
use std:: mem:: ManuallyDrop ;
10
9
use std:: fmt:: { Debug , Formatter } ;
@@ -96,15 +95,15 @@ impl CollectionManager {
96
95
* context's shadow stack, so unfreezing it while in progress
97
96
* could trigger undefined behavior!!!!!
98
97
*/
99
- context. collector . prevent_collection ( |_| {
98
+ context. collector . as_raw ( ) . prevent_collection ( |_| {
100
99
assert_eq ! ( context. state. get( ) , ContextState :: Frozen ) ;
101
100
context. state . set ( ContextState :: Active ) ;
102
101
} )
103
102
}
104
103
}
105
104
106
105
pub struct RawContext {
107
- pub ( crate ) collector : Arc < RawSimpleCollector > ,
106
+ pub ( crate ) collector : SimpleCollector ,
108
107
original_thread : ThreadId ,
109
108
// NOTE: We are Send, not Sync
110
109
pub ( super ) shadow_stack : UnsafeCell < ShadowStack > ,
@@ -129,26 +128,26 @@ impl Debug for RawContext {
129
128
}
130
129
}
131
130
impl RawContext {
132
- pub ( crate ) unsafe fn register_new ( collector : & Arc < RawSimpleCollector > ) -> ManuallyDrop < Box < Self > > {
133
- let original_thread = if collector. logger . is_trace_enabled ( ) {
131
+ pub ( crate ) unsafe fn register_new ( collector : & SimpleCollector ) -> ManuallyDrop < Box < Self > > {
132
+ let original_thread = if collector. as_raw ( ) . logger . is_trace_enabled ( ) {
134
133
ThreadId :: current ( )
135
134
} else {
136
135
ThreadId :: Nop
137
136
} ;
138
137
let mut context = ManuallyDrop :: new ( Box :: new ( RawContext {
139
- collector : collector. clone ( ) ,
138
+ collector : collector. clone_internal ( ) ,
140
139
original_thread : original_thread. clone ( ) ,
141
- logger : collector. logger . new ( o ! (
140
+ logger : collector. as_raw ( ) . logger . new ( o ! (
142
141
"original_thread" => original_thread. clone( )
143
142
) ) ,
144
143
shadow_stack : UnsafeCell :: new ( ShadowStack {
145
144
last : std:: ptr:: null_mut ( ) ,
146
145
} ) ,
147
146
state : Cell :: new ( ContextState :: Active )
148
147
} ) ) ;
149
- let old_num_total = collector. add_context ( & mut * * context) ;
148
+ let old_num_total = collector. as_raw ( ) . add_context ( & mut * * context) ;
150
149
trace ! (
151
- collector. logger, "Creating new context" ;
150
+ collector. as_raw ( ) . logger, "Creating new context" ;
152
151
"ptr" => format_args!( "{:p}" , & * * context) ,
153
152
"old_num_total" => old_num_total,
154
153
"current_thread" => & original_thread
@@ -171,11 +170,12 @@ impl RawContext {
171
170
* This assumes that parking_lot priorities pending writes
172
171
* over pending reads. The standard library doesn't guarantee this.
173
172
*/
174
- let mut guard = self . collector . state . write ( ) ;
173
+ let collector = self . collector . as_raw ( ) ;
174
+ let mut guard = collector. state . write ( ) ;
175
175
let state = & mut * guard;
176
176
// If there is not a active `PendingCollection` - create one
177
177
if state. pending . is_none ( ) {
178
- assert ! ( !self . collector. manager. collecting. compare_and_swap(
178
+ assert ! ( !collector. manager. collecting. compare_and_swap(
179
179
false , true , Ordering :: SeqCst
180
180
) ) ;
181
181
let id = state. next_pending_id ( ) ;
@@ -236,7 +236,7 @@ impl RawContext {
236
236
"state" => ?pending. state,
237
237
"collector_id" => expected_id
238
238
) ;
239
- self . collector . await_collection (
239
+ collector. await_collection (
240
240
expected_id, ptr, guard,
241
241
|state, contexts| {
242
242
let pending = state. pending . as_mut ( ) . unwrap ( ) ;
@@ -247,20 +247,20 @@ impl RawContext {
247
247
trace ! (
248
248
self . logger, "Beginning simple collection" ;
249
249
"current_thread" => FnValue ( |_| ThreadId :: current( ) ) ,
250
- "original_size" => self . collector. heap. allocator. allocated_size( ) ,
250
+ "original_size" => collector. heap. allocator. allocated_size( ) ,
251
251
"contexts" => ?contexts,
252
252
"total_contexts" => pending. total_contexts,
253
253
"state" => ?pending. state,
254
254
"collector_id" => pending. id,
255
255
) ;
256
- self . collector . perform_raw_collection ( & contexts) ;
256
+ collector. perform_raw_collection ( & contexts) ;
257
257
assert_eq ! (
258
258
pending. state,
259
259
PendingState :: InProgress
260
260
) ;
261
261
pending. state = PendingState :: Finished ;
262
262
// Now acknowledge that we're finished
263
- self . collector . acknowledge_finished_collection (
263
+ collector. acknowledge_finished_collection (
264
264
& mut state. pending , ptr
265
265
) ;
266
266
}
0 commit comments