attempting to implement os signal handling. work in progress

This commit is contained in:
hyunghwan.chung 2019-08-12 15:54:09 +00:00
parent f33af85fbc
commit f3c91bbed2
3 changed files with 34 additions and 5 deletions

View File

@ -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 |

View File

@ -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.