diff --git a/.cell/cell.toml b/.cell/cell.toml index b4abda85..e1581d24 100644 --- a/.cell/cell.toml +++ b/.cell/cell.toml @@ -2,7 +2,20 @@ extramath = "https://gitea.pockle.world/john/extramath@master" [system] -ar_timer = 60 # seconds before idle actor reclamation -actor_memory = 0 # MB of memory an actor can use; 0 for unbounded -net_service = 0.1 # seconds per net service pull -reply_timeout = 60 # seconds to hold callback for reply messages; 0 for unbounded \ No newline at end of file +# seconds before idle actor reclamation +ar_timer = 60 + +# MB of memory an actor can use; 0 for unbounded +actor_memory = 0 + +# seconds per net service pull +net_service = 0.1 + +# seconds to hold callback for reply messages; 0 for unbounded +reply_timeout = 60 + +# max number of simultaneous actors +actor_max = 10_000 + +# MB of memory each actor's stack can grow to +stack_max = 0 diff --git a/prosperon/_sdl_video.ce b/prosperon/_sdl_video.ce index 4701d3b0..6738667b 100644 --- a/prosperon/_sdl_video.ce +++ b/prosperon/_sdl_video.ce @@ -1,6 +1,5 @@ // SDL Video Actor // This actor runs on the main thread and handles all SDL video operations -log.console("TO HERE") var surface = use('surface') // Default window configuration - documents all available window options diff --git a/prosperon/main.ce b/prosperon/main.ce index 4634af24..2ab6aebf 100644 --- a/prosperon/main.ce +++ b/prosperon/main.ce @@ -73,8 +73,6 @@ var camera = { } var util = use('util') -log.console(util) -log.console(camera) var cammy = util.camera_globals(camera) var graphics diff --git a/scripts/engine.cm b/scripts/engine.cm index 6c39fe38..f3781a8e 100644 --- a/scripts/engine.cm +++ b/scripts/engine.cm @@ -627,7 +627,13 @@ function turn(msg) send_messages() } -actor_mod.register_actor(cell.id, turn, cell.args.main, config.system) +actor_mod.register_actor(cell.id, turn, cell.args.main, config.system.ar_timer) + +if (config.system.actor_memory) + js.mem_limit(config.system.actor_memory) + +if (config.system.stack_max) + js.max_stacksize(config.system.stack_max); overling = cell.args.overling root = cell.args.root @@ -773,8 +779,6 @@ var val = js.eval(cell.args.program, prog_script)($_, cell.args.arg) if (val) throw new Error('Program must not return anything'); -log.console("WAYDOWN") - send_messages() })() \ No newline at end of file diff --git a/source/cell.c b/source/cell.c index 4189ac0a..c19e51a8 100644 --- a/source/cell.c +++ b/source/cell.c @@ -105,7 +105,6 @@ void actor_free(cell_rt *actor) JSContext *js = actor->context; - JS_FreeValue(js, actor->cycle_fn); JS_FreeValue(js, actor->idx_buffer); JS_FreeValue(js, actor->message_handle); JS_FreeValue(js, actor->on_exception); @@ -181,7 +180,6 @@ void js_dofree(JSRuntime *rt, void *opaque, void *ptr) js_free_rt(rt, ptr); } -SDL_ThreadID main_thread = 0; SDL_TLSID prosperon_id; #ifdef TRACY_ENABLE @@ -329,7 +327,6 @@ cell_rt *create_actor(void *wota, void (*hook)(JSContext*)) { cell_rt *actor = calloc(sizeof(*actor), 1); actor->init_wota = wota; - actor->cycle_fn = JS_UNDEFINED; actor->idx_buffer = JS_UNDEFINED; actor->message_handle = JS_UNDEFINED; actor->unneeded = JS_UNDEFINED; @@ -365,7 +362,7 @@ cell_rt *get_actor(char *id) return actor; } -const char *register_actor(const char *id, cell_rt *actor, int mainthread, JSValue config) +const char *register_actor(const char *id, cell_rt *actor, int mainthread, double ar) { SDL_LockMutex(actors_mutex); if (shgeti(actors, id) != -1) { @@ -374,6 +371,7 @@ const char *register_actor(const char *id, cell_rt *actor, int mainthread, JSVal } actor->main_thread_only = mainthread; actor->id = strdup(id); + actor->ar_secs = ar; shput(actors, id, actor); SDL_UnlockMutex(actors_mutex); return NULL; @@ -446,14 +444,9 @@ void set_actor_state(cell_rt *actor) } END: - if (actor->state == ACTOR_IDLE && !actor->ar && !has_upcoming) { - if (JS_IsUndefined(actor->unneeded)) - actor->ar = SDL_AddTimerNS(SDL_SECONDS_TO_NS(5), actor_remove_cb, actor); - else { - if (!isinf(actor->unneeded_secs)) - actor->ar = SDL_AddTimerNS(SDL_SECONDS_TO_NS(actor->unneeded_secs), actor_remove_cb, actor); - } - } + if (actor->state == ACTOR_IDLE && !actor->ar && !has_upcoming) + actor->ar = SDL_AddTimerNS(SDL_SECONDS_TO_NS(actor->ar_secs), actor_remove_cb, actor); + SDL_UnlockMutex(actor->msg_mutex); } @@ -1517,7 +1510,6 @@ int main(int argc, char **argv) tracy_profiling_enabled = profile_enabled; #endif - main_thread = SDL_GetCurrentThreadID(); int cores = SDL_GetNumLogicalCPUCores(); prosperon = argv[0]; diff --git a/source/cell.h b/source/cell.h index 6503188e..038c9e14 100644 --- a/source/cell.h +++ b/source/cell.h @@ -4,6 +4,8 @@ #include #include "quickjs.h" #include "qjs_macros.h" +#include "qjs_blob.h" +#include "blob.h" #define STATE_VECTOR_LENGTH 624 #define STATE_VECTOR_M 397 @@ -31,12 +33,10 @@ typedef struct { typedef struct cell_rt { JSContext *context; - JSValue cycle_fn; JSValue idx_buffer; JSValue on_exception; JSValue message_handle; - JSValue unneeded; - + void *init_wota; ModuleEntry *module_registry; @@ -49,8 +49,7 @@ typedef struct cell_rt { char *id; MTRand mrand; - double unneeded_secs; - double ar_secs; + int idx_count; /* The “mailbox” for incoming messages + a dedicated lock for it: */ @@ -62,7 +61,10 @@ typedef struct cell_rt { struct { Uint32 key; JSValue value; } *timers; int state; - Uint32 ar; + Uint32 ar; // timer for unneeded + double ar_secs; // time for unneeded + JSValue unneeded; // fn to call before unneeded + int need_stop; int disrupt; int main_thread_only; @@ -73,13 +75,12 @@ typedef struct cell_rt { const char *name; // human friendly name } cell_rt; -extern SDL_ThreadID main_thread; extern SDL_TLSID prosperon_id; extern cell_rt *root_cell; // first actor in the system cell_rt *create_actor(void *wota, void (*hook)(JSContext*)); -const char *register_actor(const char *id, cell_rt *actor, int mainthread, JSValue config); +const char *register_actor(const char *id, cell_rt *actor, int mainthread, double ar); void actor_disrupt(cell_rt *actor); const char *send_message(const char *id, void *msg); diff --git a/source/qjs_actor.c b/source/qjs_actor.c index be639f8f..826ae657 100644 --- a/source/qjs_actor.c +++ b/source/qjs_actor.c @@ -100,7 +100,9 @@ JSC_CCALL(os_mailbox_push, JSC_CCALL(os_register_actor, cell_rt *rt = JS_GetContextOpaque(js); const char *id = JS_ToCString(js, argv[0]); - const char *err = register_actor(id, rt, JS_ToBool(js, argv[2]), argv[3]); + double ar; + JS_ToFloat64(js, &ar, argv[3]); + const char *err = register_actor(id, rt, JS_ToBool(js, argv[2]), ar); if (err) return JS_ThrowInternalError(js, "Could not register actor: %s", err); rt->message_handle = JS_DupValue(js, argv[1]); rt->context = js; @@ -126,7 +128,7 @@ JSC_CCALL(os_unneeded, } actor->unneeded = JS_DupValue(js, argv[0]); - JS_ToFloat64(js, &actor->unneeded_secs, argv[1]); + JS_ToFloat64(js, &actor->ar_secs, argv[1]); END: if (actor->ar) {