#ifndef PROSPERON_H #define PROSPERON_H #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 #define ACTOR_IDLE 0 #define ACTOR_READY 1 #define ACTOR_RUNNING 2 #define ACTOR_EXHAUSTED 3 #define ACTOR_RECLAIMING 4 #define ACTOR_SLOW 5 typedef JSValue (*MODULEFN)(JSContext *js); extern int tracy_profiling_enabled; typedef struct tagMTRand { uint32_t mt[STATE_VECTOR_LENGTH]; int32_t index; } MTRand; typedef struct { const char *name; MODULEFN fn; } ModuleEntry; typedef struct cell_rt { JSContext *context; JSValue idx_buffer; JSValue on_exception; JSValue message_handle; void *init_wota; ModuleEntry *module_registry; JSValue *js_swapchains; /* Protects JSContext usage */ SDL_Mutex *mutex; SDL_Mutex *turn; char *id; MTRand mrand; int idx_count; /* The “mailbox” for incoming messages + a dedicated lock for it: */ void **messages; JSValue *events; SDL_Mutex *msg_mutex; /* For messages queue only */ /* CHANGED FOR EVENTS: a separate lock for the actor->events queue */ struct { Uint32 key; JSValue value; } *timers; int state; 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; JSAtom actor_sym; JSAtom doc_sym; const char *name; // human friendly name } cell_rt; 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, double ar); void actor_disrupt(cell_rt *actor); const char *send_message(const char *id, void *msg); Uint32 actor_timer_cb(cell_rt *actor, SDL_TimerID id, Uint32 interval); JSValue js_actor_delay(JSContext *js, JSValue self, int argc, JSValue *argv); JSValue js_actor_removetimer(JSContext *js, JSValue self, int argc, JSValue *argv); void script_startup(cell_rt *rt, void (*hook)(JSContext*)); void script_evalf(JSContext *js, const char *format, ...); JSValue script_eval(JSContext *js, const char *file, const char *script); int uncaught_exception(JSContext *js, JSValue v); int actor_exists(const char *id); cell_rt *get_actor(char *id); void set_actor_state(cell_rt *actor); int JS_ArrayLength(JSContext *js, JSValue a); int prosperon_mount_core(void); // Event watchers for SDL events extern char **event_watchers; extern SDL_Mutex *event_watchers_mutex; #endif