signal kill works
This commit is contained in:
@@ -66,7 +66,8 @@ static unsigned char *zip_buffer_global = NULL;
|
|||||||
static char *prosperon = NULL;
|
static char *prosperon = NULL;
|
||||||
cell_rt *root_cell = NULL;
|
cell_rt *root_cell = NULL;
|
||||||
|
|
||||||
SDL_AtomicInt waiting_threads;
|
static SDL_AtomicInt waiting_threads;
|
||||||
|
static SDL_AtomicInt shutting_down;
|
||||||
|
|
||||||
static SDL_Thread **runners = NULL;
|
static SDL_Thread **runners = NULL;
|
||||||
|
|
||||||
@@ -77,8 +78,13 @@ static inline uint64_t now_ns()
|
|||||||
|
|
||||||
static void exit_handler(void)
|
static void exit_handler(void)
|
||||||
{
|
{
|
||||||
|
SDL_LockMutex(queue_mutex); /* 1. take the lock */
|
||||||
|
SDL_SetAtomicInt(&shutting_down, 1); /* 2. store *inside* CS */
|
||||||
|
SDL_BroadcastCondition(queue_cond); /* 3. wake the waiters */
|
||||||
|
SDL_UnlockMutex(queue_mutex); /* 4. release – H-B created */
|
||||||
|
SDL_SetAtomicInt(&shutting_down, 1);
|
||||||
|
|
||||||
int status;
|
int status;
|
||||||
SDL_BroadcastCondition(queue_cond);
|
|
||||||
for (int i = 0; i < arrlen(runners); i++)
|
for (int i = 0; i < arrlen(runners); i++)
|
||||||
SDL_WaitThread(runners[i], &status);
|
SDL_WaitThread(runners[i], &status);
|
||||||
|
|
||||||
@@ -720,7 +726,7 @@ int uncaught_exception(JSContext *js, JSValue v)
|
|||||||
|
|
||||||
static int actor_runner(void *data)
|
static int actor_runner(void *data)
|
||||||
{
|
{
|
||||||
while (1) {
|
while (!SDL_GetAtomicInt(&shutting_down)) {
|
||||||
SDL_LockMutex(queue_mutex);
|
SDL_LockMutex(queue_mutex);
|
||||||
cell_rt *actor = NULL;
|
cell_rt *actor = NULL;
|
||||||
for (int i = 0; i < arrlen(ready_queue); i++) {
|
for (int i = 0; i < arrlen(ready_queue); i++) {
|
||||||
@@ -739,7 +745,7 @@ static int actor_runner(void *data)
|
|||||||
SDL_WaitCondition(queue_cond, queue_mutex);
|
SDL_WaitCondition(queue_cond, queue_mutex);
|
||||||
SDL_AddAtomicInt(&waiting_threads, -1);
|
SDL_AddAtomicInt(&waiting_threads, -1);
|
||||||
SDL_UnlockMutex(queue_mutex);
|
SDL_UnlockMutex(queue_mutex);
|
||||||
continue;
|
if (SDL_GetAtomicInt(&shutting_down)) return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -747,7 +753,6 @@ static int actor_runner(void *data)
|
|||||||
|
|
||||||
static void signal_handler(int sig)
|
static void signal_handler(int sig)
|
||||||
{
|
{
|
||||||
exit_handler();
|
|
||||||
const char *str = NULL;
|
const char *str = NULL;
|
||||||
switch (sig) {
|
switch (sig) {
|
||||||
case SIGABRT: str = "SIGABRT"; break;
|
case SIGABRT: str = "SIGABRT"; break;
|
||||||
@@ -780,12 +785,13 @@ static void loop()
|
|||||||
queue_cond = SDL_CreateCondition();
|
queue_cond = SDL_CreateCondition();
|
||||||
actors_mutex = SDL_CreateMutex();
|
actors_mutex = SDL_CreateMutex();
|
||||||
SDL_SetAtomicInt(&waiting_threads, 0);
|
SDL_SetAtomicInt(&waiting_threads, 0);
|
||||||
|
SDL_SetAtomicInt(&shutting_down, 0);
|
||||||
|
|
||||||
timer_init();
|
timer_init();
|
||||||
|
|
||||||
add_runners(SDL_GetNumLogicalCPUCores()-1);
|
add_runners(SDL_GetNumLogicalCPUCores()-1);
|
||||||
|
|
||||||
while (1) {
|
while (!SDL_GetAtomicInt(&shutting_down)) {
|
||||||
process_due_timers();
|
process_due_timers();
|
||||||
|
|
||||||
SDL_LockMutex(queue_mutex);
|
SDL_LockMutex(queue_mutex);
|
||||||
@@ -814,7 +820,7 @@ static void loop()
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDL_LockMutex(queue_mutex);
|
SDL_LockMutex(queue_mutex);
|
||||||
SDL_WaitConditionTimeout(queue_cond, queue_mutex, 100);
|
SDL_WaitConditionTimeout(queue_cond, queue_mutex, to_ns);
|
||||||
SDL_UnlockMutex(queue_mutex);
|
SDL_UnlockMutex(queue_mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -936,3 +942,12 @@ int actor_exists(const char *id)
|
|||||||
else
|
else
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int JS_ArrayLength(JSContext *js, JSValue a)
|
||||||
|
{
|
||||||
|
JSValue length = JS_GetPropertyStr(js, a, "length");
|
||||||
|
int len;
|
||||||
|
JS_ToInt32(js,&len,length);
|
||||||
|
JS_FreeValue(js,length);
|
||||||
|
return len;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user