1
1
use std:: time:: Instant ;
2
2
use std:: { fmt, ops:: Deref , ptr:: NonNull } ;
3
3
4
- use crate :: object:: gc:: { deadlock_handler, Color , GcObjPtr , GcStatus } ;
4
+ use crate :: object:: gc:: { deadlock_handler, Color , GcObjPtr , GcStatus , GcTrace , GcObj , GcObjRef } ;
5
5
use crate :: PyObject ;
6
6
7
7
use rustpython_common:: {
@@ -97,7 +97,7 @@ impl From<GcResult> for usize {
97
97
}
98
98
99
99
pub struct CcSync {
100
- roots : PyMutex < Vec < WrappedPtr < dyn GcObjPtr > > > ,
100
+ roots : PyMutex < Vec < WrappedPtr < GcObj > > > ,
101
101
/// for stop the world, will be try to check lock every time deref ObjecteRef
102
102
/// to achive pausing
103
103
pub pause : PyRwLock < ( ) > ,
@@ -119,7 +119,7 @@ impl std::fmt::Debug for CcSync {
119
119
}
120
120
121
121
// TODO: change to use PyInner<Erased> directly
122
- type ObjRef < ' a > = & ' a dyn GcObjPtr ;
122
+
123
123
124
124
impl CcSync {
125
125
thread_local ! {
@@ -184,7 +184,7 @@ impl CcSync {
184
184
false
185
185
}
186
186
}
187
- pub fn increment ( & self , obj : ObjRef ) {
187
+ pub fn increment ( & self , obj : GcObjRef ) {
188
188
if obj. header ( ) . is_leaked ( ) {
189
189
// by define a leaked object's rc should not change?
190
190
return ;
@@ -197,7 +197,7 @@ impl CcSync {
197
197
/// # Safety
198
198
/// if the last ref to a object call decrement() on object,
199
199
/// then this object should be considered freed.
200
- pub unsafe fn decrement ( & self , obj : ObjRef ) -> GcStatus {
200
+ pub unsafe fn decrement ( & self , obj : GcObjRef ) -> GcStatus {
201
201
if obj. header ( ) . is_leaked ( ) {
202
202
// a leaked object should always keep
203
203
return GcStatus :: ShouldKeep ;
@@ -222,7 +222,7 @@ impl CcSync {
222
222
}
223
223
}
224
224
225
- unsafe fn release ( & self , obj : ObjRef ) -> GcStatus {
225
+ unsafe fn release ( & self , obj : GcObjRef ) -> GcStatus {
226
226
// because drop obj itself will drop all ObjRef store by object itself once more,
227
227
// so balance out in here
228
228
// by doing nothing
@@ -244,7 +244,7 @@ impl CcSync {
244
244
}
245
245
}
246
246
247
- fn possible_root ( & self , obj : ObjRef ) {
247
+ fn possible_root ( & self , obj : GcObjRef ) {
248
248
if obj. header ( ) . color ( ) != Color :: Purple {
249
249
obj. header ( ) . set_color ( Color :: Purple ) ;
250
250
// prevent add to buffer for multiple times
@@ -254,7 +254,7 @@ impl CcSync {
254
254
// lock here to serialize access to root&gc
255
255
let mut roots = self . roots . lock ( ) ;
256
256
* buffered = true ;
257
- roots. push ( obj . as_ptr ( ) . into ( ) ) ;
257
+ roots. push ( NonNull :: from ( obj ) . into ( ) ) ;
258
258
}
259
259
}
260
260
}
@@ -379,14 +379,14 @@ impl CcSync {
379
379
380
380
len_white
381
381
}
382
- fn collect_white ( & self , obj : ObjRef , white : & mut Vec < NonNull < dyn GcObjPtr > > ) {
382
+ fn collect_white ( & self , obj : GcObjRef , white : & mut Vec < NonNull < GcObj > > ) {
383
383
if obj. header ( ) . color ( ) == Color :: White && !obj. header ( ) . buffered ( ) {
384
384
obj. header ( ) . set_color ( Color :: BlackFree ) ;
385
385
obj. trace ( & mut |ch| self . collect_white ( ch, white) ) ;
386
- white. push ( obj . as_ptr ( ) ) ;
386
+ white. push ( NonNull :: from ( obj ) ) ;
387
387
}
388
388
}
389
- fn mark_gray ( & self , obj : ObjRef ) {
389
+ fn mark_gray ( & self , obj : GcObjRef ) {
390
390
if obj. header ( ) . color ( ) != Color :: Gray {
391
391
obj. header ( ) . set_color ( Color :: Gray ) ;
392
392
obj. trace ( & mut |ch| {
@@ -395,7 +395,7 @@ impl CcSync {
395
395
} ) ;
396
396
}
397
397
}
398
- fn scan ( & self , obj : ObjRef ) {
398
+ fn scan ( & self , obj : GcObjRef ) {
399
399
if obj. header ( ) . color ( ) == Color :: Gray {
400
400
if obj. rc ( ) > 0 {
401
401
self . scan_black ( obj)
@@ -407,7 +407,7 @@ impl CcSync {
407
407
}
408
408
}
409
409
}
410
- fn scan_black ( & self , obj : ObjRef ) {
410
+ fn scan_black ( & self , obj : GcObjRef ) {
411
411
obj. header ( ) . set_color ( Color :: Black ) ;
412
412
obj. trace ( & mut |ch| {
413
413
ch. header ( ) . inc ( ) ;
0 commit comments