redefined gcfin_proc and ossig_proc as class instance variables of System

This commit is contained in:
hyunghwan.chung 2019-11-04 08:44:23 +00:00
parent dbf066695b
commit 546c766a39
6 changed files with 161 additions and 66 deletions

View File

@ -13,6 +13,8 @@ class System(Apex)
var(#class) asyncsg. var(#class) asyncsg.
var(#class) gcfin_sem. var(#class) gcfin_sem.
var(#class) gcfin_should_exit := false. var(#class) gcfin_should_exit := false.
var(#class) gcfin_proc.
var(#class) ossig_proc.
var(#class) shr. // signal handler registry var(#class) shr. // signal handler registry
pooldic Log pooldic Log
@ -62,7 +64,7 @@ class System(Apex)
method(#class) startup(class_name, method_name) method(#class) startup(class_name, method_name)
{ {
| class ret gcfin_proc ossig_proc | | class ret |
System gc. System gc.
@ -77,11 +79,11 @@ class System(Apex)
// start the gc finalizer process and os signal handler process // start the gc finalizer process and os signal handler process
//[ self __gc_finalizer ] fork. //[ self __gc_finalizer ] fork.
//[ self __os_sig_handler ] fork. //[ self __os_sig_handler ] fork.
gcfin_proc := [ self __gc_finalizer ] newProcess. self.gcfin_proc := [ self __gc_finalizer ] newProcess.
ossig_proc := [ :caller | self __os_sig_handler: caller ] newProcess(thisProcess). self.ossig_proc := [ :caller | self __os_sig_handler: caller ] newProcess(thisProcess).
gcfin_proc resume. self.gcfin_proc resume.
ossig_proc resume. self.ossig_proc resume.
[ [
// TODO: change the method signature to variadic and pass extra arguments to perform??? // TODO: change the method signature to variadic and pass extra arguments to perform???
@ -145,6 +147,7 @@ class System(Apex)
self.gcfin_sem signal. // in case the process is stuck in wait. self.gcfin_sem signal. // in case the process is stuck in wait.
self.gcfin_sem unsignal. self.gcfin_sem unsignal.
System logNl: 'End of GC finalization process ' & (thisProcess id) asString. System logNl: 'End of GC finalization process ' & (thisProcess id) asString.
self.gcfin_proc := nil.
]. ].
} }
@ -203,7 +206,8 @@ class System(Apex)
2 -> __os_sig_handler 2 -> __os_sig_handler
3 .. -> other processes started by application. 3 .. -> other processes started by application.
*/ */
proc := System _findProcessByIdGreaterThan: 2. /* TODO: this loop is error-prone as it can't handle when the processs id wraps back and the id of gcfin_proc and ossig_proc gets bigger than normal child processes */
proc := System _findProcessByIdGreaterThan: (self.ossig_proc id).
while (proc notError) while (proc notError)
{ {
pid := proc id. pid := proc id.
@ -221,6 +225,7 @@ class System(Apex)
self.gcfin_should_exit := true. self.gcfin_should_exit := true.
self.gcfin_sem signal. // wake the gcfin process. self.gcfin_sem signal. // wake the gcfin process.
self.ossig_proc := nil.
self _halting. // inform VM that it should get ready for halting. self _halting. // inform VM that it should get ready for halting.
]. ].
} }

View File

@ -405,7 +405,7 @@ static kernel_class_info_t kernel_classes[] =
{ 6, { 6,
{ 'S','y','s','t','e','m' }, { 'S','y','s','t','e','m' },
0, 0,
4, /* asyncsg, gcfin_sem, gcfin_should_exit, shr */ 6, /* asyncsg, gcfin_sem, gcfin_should_exit, gcfin_proc, ossig_proc, shr */
0, 0,
0, 0,
MOO_OBJ_TYPE_OOP, MOO_OBJ_TYPE_OOP,

View File

@ -6,6 +6,7 @@ blddir=${topdir}/bld/emcc
emcc -Wall -O2 -g \ emcc -Wall -O2 -g \
${blddir}/lib/.libs/libmoo.a \ ${blddir}/lib/.libs/libmoo.a \
${blddir}/lib/.libs/libmoox.a \
${topdir}/wasm/main.c \ ${topdir}/wasm/main.c \
-DMOO_HAVE_CFG_H \ -DMOO_HAVE_CFG_H \
-I${blddir}/lib \ -I${blddir}/lib \
@ -16,5 +17,7 @@ emcc -Wall -O2 -g \
--embed-file ${topdir}/kernel/ \ --embed-file ${topdir}/kernel/ \
--pre-js ${topdir}/wasm/moo.cb.js --pre-js ${topdir}/wasm/moo.cb.js
cp -pf ${topdir}/wasm/moo.html . ##cp -pf ${topdir}/wasm/moo.html .
cp -pf ${topdir}/wasm/moo.worker.js . ##cp -pf ${topdir}/wasm/moo.worker.js .
ln -sf ${topdir}/wasm/moo.html moo.html
ln -sf ${topdir}/wasm/moo.worker.js moo.worker.js

View File

@ -110,3 +110,20 @@ EMSCRIPTEN_KEEPALIVE int open_moo (void)
#endif #endif
} }
EMSCRIPTEN_KEEPALIVE moo_bch_t* get_errmsg_from_moo (moo_t* moo)
{
#if defined(MOO_OOCH_IS_UCH)
/* TODO: no static.... error check... */
static moo_bch_t bm[256];
moo_oow_t bl = MOO_COUNTOF(bm);
moo_convutobcstr (moo, moo_geterrmsg(moo), MOO_NULL, bm, &bl);
return bm;
#else
return moo_geterrmsg(moo);
#endif
}
EMSCRIPTEN_KEEPALIVE void switch_process_in_moo (moo_t* moo)
{
moo_switchprocess(moo);
}

View File

@ -3,7 +3,9 @@
<head><meta charset="utf-8" /></head> <head><meta charset="utf-8" /></head>
<body> <body>
<input type="button" value="Test" onclick="do_test();" /> <input type="button" value="Open" onclick="do_open();" />
<input type="button" value="Run" onclick="do_run();" />
<input type="button" value="Close" onclick="do_close();" />
<script type="text/javascript"> <script type="text/javascript">
var g_WebWorker = new Worker("moo.worker.js"); var g_WebWorker = new Worker("moo.worker.js");
@ -12,6 +14,16 @@
alert ('No web assebly support in this browser'); alert ('No web assebly support in this browser');
} }
/*
window.addEventListener('beforeunload', function(event) {
//g_WebWorker.terminate ();
//g_WebWorkder = null;
var confirmationMessage = "\o/";
(event || window.event).returnValue = confirmationMessage; //Gecko + IE
return confirmationMessage;
});
*/
g_WebWorker.onerror = function (evt) { g_WebWorker.onerror = function (evt) {
console.log(`Error from Web Worker: ${evt.message}`); console.log(`Error from Web Worker: ${evt.message}`);
@ -21,9 +33,19 @@
console.log(`Message from the Web Worker:\n\n ${evt.data}`); console.log(`Message from the Web Worker:\n\n ${evt.data}`);
}; };
function do_test() function do_open()
{ {
g_WebWorker.postMessage({ "cmd": "test-moo", "data": "nothing as of now.." }); g_WebWorker.postMessage({ "cmd": "open-moo", "data": "nothing as of now.." });
}
function do_run()
{
g_WebWorker.postMessage({ "cmd": "run-moo", "data": "nothing as of now.." });
}
function do_close()
{
g_WebWorker.postMessage({ "cmd": "close-moo", "data": "nothing as of now.." });
} }
</script> </script>

View File

@ -1,60 +1,108 @@
self.importScripts('libmoo.js'); self.importScripts('libmoo.js');
self.__ready = false; self.libmoo = null;
self.moo = null;
Module.noExitRuntime = false;
Module.onExit = function (status) {
console.log ('exiting....');
};
Module.onRuntimeInitialized = function() Module.onRuntimeInitialized = function()
{ {
self.__ready = true;
console.log ('runtime is ready now...'); console.log ('runtime is ready now...');
}
const libmoo = { self.libmoo = {
open: Module.cwrap('moo_openstd', 'number', ['number', 'number', 'number']), open: Module.cwrap('moo_openstd', 'number', ['number', 'number', 'number']),
close: Module.cwrap('moo_close', '', ['number']), close: Module.cwrap('moo_close', '', ['number']),
ignite: Module.cwrap('moo_ignite', 'number', ['number', 'number']), ignite: Module.cwrap('moo_ignite', 'number', ['number', 'number']),
initdbgi: Module.cwrap('moo_initdbgi', 'number', ['number', 'number']), initdbgi: Module.cwrap('moo_initdbgi', 'number', ['number', 'number']),
compilefile: Module.cwrap('moo_compilefileb', 'number', ['number', 'string']), compilefile: Module.cwrap('moo_compilefileb', 'number', ['number', 'string']),
invoke: Module.cwrap('moo_invokebynameb', 'number', ['number', 'string', 'string']) invoke: Module.cwrap('moo_invokebynameb', 'number', ['number', 'string', 'string']),
geterrmsg: Module.cwrap('get_errmsg_from_moo', 'string', ['number']),
switchprocess: Module.cwrap('switch_process_in_moo', 'undefined', ['number'])
};
}; };
/*
var log_write = Module.addFunction(function() {
});
*/
//self.onmessage = function (evt) { //self.onmessage = function (evt) {
self.addEventListener ('message', function (evt) { self.addEventListener ('message', function (evt) {
var objData = evt.data; var objData = evt.data;
var cmd = objData.cmd; var cmd = objData.cmd;
if (cmd === "test-moo") if (cmd === "run-moo")
{ {
//var x = Module.ccall('moo_openstd', [0, null, null]); //var x = Module.ccall('moo_openstd', [0, null, null]);
//Module.ccall('moo_close', x); //Module.ccall('moo_close', x);
if (self.__ready) if (self.moo !== null)
{ {
var moo, tmp; var tmp, msg = "";
var msg = ""; //var ticker;
moo = libmoo.open(0, null, null); // while self.libmoo.invoke() is running, setInterval() is unable to trigger the timed event.
msg = msg.concat("open - " + moo); // it's an architectural issue. emscripten doesn't implement setitimer() yet.
// the moo program should 'yield' manually for process switching for now.
//ticker = setInterval(function() { self.libmoo.switchprocess (self.moo); console.log("ticking"); }, 100);
tmp = libmoo.ignite(moo, 5000000); tmp = self.libmoo.invoke(self.moo, "MyObject", "main");
msg = msg.concat(" ignite - " + tmp);
tmp = libmoo.initdbgi(moo, 102400);
msg = msg.concat(" initdgbi - " + tmp);
tmp = libmoo.compilefile(moo, "kernel/t.moo");
msg = msg.concat(" compilefile - " + tmp);
tmp = libmoo.invoke(moo, "MyObject", "main");
msg = msg.concat("invoke - " + tmp); msg = msg.concat("invoke - " + tmp);
self.postMessage (msg); //clearInterval (ticker);
libmoo.close (moo); self.postMessage (msg);
}
else
{
self.postMessage ("not open");
}
}
else if (cmd == "open-moo")
{
if (self.libmoo === null)
{
self.postMessage ("not ready");
}
else if (self.moo === null)
{
var tmp, msg = "";
self.moo = self.libmoo.open(0, null, null);
msg = msg.concat("open - " + moo);
tmp = self.libmoo.ignite(self.moo, 5000000);
msg = msg.concat(" ignite - " + tmp);
tmp = self.libmoo.initdbgi(self.moo, 102400);
msg = msg.concat(" initdgbi - " + tmp);
tmp = self.libmoo.compilefile(self.moo, "kernel/t.moo");
if (tmp == -1)
{
msg = msg.concat(" compilefile - " + self.libmoo.geterrmsg(self.moo));
}
else
{
msg = msg.concat(" compilefile - " + tmp);
}
self.postMessage (msg);
}
else
{
self.postMessage ("already open");
}
}
else if (cmd == "close-moo")
{
if (self.moo !== null)
{
self.libmoo.close (self.moo);
self.moo = null;
self.postMessage ("close ok");
}
else
{
self.postMessage ("already closed");
} }
} }
}); });