Skip to content
Snippets Groups Projects
Commit 6a7108a5 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Use pthread once for jsrt initializtion.

Does not fix the NetBSD issue, but should be done anyway.
parent 392f1e38
No related branches found
No related tags found
No related merge requests found
Pipeline #5490 passed
......@@ -25,18 +25,24 @@ static void trigger_thread(void *args)
}
}
static void
jsrt_init(void)
{
initialized=TRUE;
pthread_mutex_init(&jsrt_mutex, NULL);
pthread_mutex_lock(&jsrt_mutex);
listInit(&rt_list, 0);
pthread_mutex_unlock(&jsrt_mutex);
_beginthread(trigger_thread, TRIGGER_THREAD_STACK_SIZE, NULL);
}
static pthread_once_t jsrt_once = PTHREAD_ONCE_INIT;
JSRuntime * jsrt_GetNew(int maxbytes, unsigned long timeout, const char *filename, long line)
{
JSRuntime *ret;
if(!initialized) {
initialized=TRUE;
pthread_mutex_init(&jsrt_mutex, NULL);
pthread_mutex_lock(&jsrt_mutex);
listInit(&rt_list, 0);
_beginthread(trigger_thread, TRIGGER_THREAD_STACK_SIZE, NULL);
} else
pthread_mutex_lock(&jsrt_mutex);
pthread_once(&jsrt_once, jsrt_init);
pthread_mutex_lock(&jsrt_mutex);
ret=JS_NewRuntime(maxbytes);
listPushNode(&rt_list, ret);
pthread_mutex_unlock(&jsrt_mutex);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment