diff --git a/moo/kernel/FFI.moo b/moo/kernel/FFI.moo index 90bbeb0..06c0e8e 100644 --- a/moo/kernel/FFI.moo +++ b/moo/kernel/FFI.moo @@ -25,8 +25,14 @@ class FFI(Object) { self.funcs := Dictionary new. self.ffi := _FFI new. + //self addToBeFinalized. } + /*method finalize + { + self close + }*/ + method open: name { | x | diff --git a/moo/kernel/System.moo b/moo/kernel/System.moo index 1dc357d..09b2a0b 100644 --- a/moo/kernel/System.moo +++ b/moo/kernel/System.moo @@ -55,6 +55,7 @@ class System(Apex) // start the gc finalizer process [ self __gc_finalizer ] fork. + [ self __os_signal_handler ] fork. // TODO: change the method signature to variadic and pass extra arguments to perform??? ret := class perform: method_name. @@ -70,7 +71,7 @@ class System(Apex) gc := false. gcfin_sem := Semaphore new. - gcfin_sem signalOnGCFin. + gcfin_sem signalOnGCFin. // tell VM to signal this semaphore when it schedules gc finalization. [ while (true) @@ -100,10 +101,7 @@ class System(Apex) gc := false. }. - //System logNl: '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^gc_waiting....'. - //System sleepForSecs: 1. // TODO: wait on semaphore instead.. gcfin_sem wait. - //System logNl: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX gc_waitED....'. } ] ensure: [ gcfin_sem unsignal. @@ -111,6 +109,31 @@ class System(Apex) ]. } + method(#class) __os_signal_handler + { + | os_sig_sem | + + os_sig_sem := Semaphore new. + //os_sig_sem signalOnSystemSignal. + + [ + while (true) + { + if (Processor should_exit) + { + System logNl: 'Exiting the GC finalization process ' & (thisProcess id) asString. + break. + }. + + os_sig_sem wait. + } + ] + ensure: [ + os_sig_sem unsignal. + System logNl: 'End of OS signal handler process ' & (thisProcess id) asString. + ]. + } + method(#class,#primitive) _popCollectable. method(#class,#primitive) collectGarbage. method(#class,#primitive) gc. diff --git a/moo/lib/exec.c b/moo/lib/exec.c index 8192406..6dbcd9d 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -4774,7 +4774,7 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) { signal_sem_gcfin: MOO_LOG0 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Signaled GCFIN semaphore\n"); - proc = signal_semaphore (moo, moo->sem_gcfin); + proc = signal_semaphore(moo, moo->sem_gcfin); if (moo->processor->active == moo->nil_process && (moo_oop_t)proc != moo->_nil) {