File tree 2 files changed +23
-0
lines changed 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,11 @@ pub extern "C" fn mmtk_enable_collection() {
97
97
memory_manager:: enable_collection ( & SINGLETON )
98
98
}
99
99
100
+ #[ no_mangle]
101
+ pub extern "C" fn mmtk_plan_name ( ) -> * const libc:: c_char {
102
+ crate :: binding ( ) . get_plan_name_c ( )
103
+ }
104
+
100
105
#[ no_mangle]
101
106
pub extern "C" fn mmtk_used_bytes ( ) -> usize {
102
107
memory_manager:: used_bytes ( & SINGLETON )
Original file line number Diff line number Diff line change
1
+ use std:: ffi:: CString ;
1
2
use std:: ptr:: null;
3
+ use std:: sync:: Mutex ;
2
4
5
+ use crate :: SINGLETON ;
3
6
use crate :: abi;
4
7
use crate :: finalize;
5
8
6
9
pub struct RubyBinding {
7
10
pub upcalls : * const abi:: RubyUpcalls ,
8
11
pub finalizer_processor : finalize:: FinalizerProcessor ,
12
+ pub plan_name : Mutex < Option < CString > > ,
9
13
}
10
14
11
15
unsafe impl Sync for RubyBinding { }
@@ -15,6 +19,7 @@ impl RubyBinding {
15
19
Self {
16
20
upcalls : null ( ) ,
17
21
finalizer_processor : finalize:: FinalizerProcessor :: new ( ) ,
22
+ plan_name : Mutex :: new ( None ) ,
18
23
}
19
24
}
20
25
@@ -25,4 +30,17 @@ impl RubyBinding {
25
30
pub fn upcalls ( & self ) -> & ' static abi:: RubyUpcalls {
26
31
unsafe { & * self . upcalls as & ' static abi:: RubyUpcalls }
27
32
}
33
+
34
+ pub fn get_plan_name_c ( & self ) -> * const libc:: c_char {
35
+ let mut plan_name = self . plan_name . lock ( ) . unwrap ( ) ;
36
+ if plan_name. is_none ( ) {
37
+ let name_string = format ! ( "{:?}" , SINGLETON . get_options( ) . plan. value) ;
38
+ let c_string = CString :: new ( name_string) . unwrap_or_else ( |e| {
39
+ panic ! ( "Failed converting plan name to CString: {}" ,
40
+ e)
41
+ } ) ;
42
+ * plan_name = Some ( c_string) ;
43
+ }
44
+ plan_name. as_deref ( ) . unwrap ( ) . as_ptr ( )
45
+ }
28
46
}
You can’t perform that action at this time.
0 commit comments