mirror of
https://github.com/janet-lang/janet
synced 2024-11-25 01:37:19 +00:00
Create pthread threads with detached attribute.
Rather than calling pthread_detach on a default thread.
This commit is contained in:
parent
76be8006a4
commit
a3a42eebea
@ -557,6 +557,10 @@ void janet_ev_init_common(void) {
|
|||||||
janet_vm.tq_capacity = 0;
|
janet_vm.tq_capacity = 0;
|
||||||
janet_table_init_raw(&janet_vm.threaded_abstracts, 0);
|
janet_table_init_raw(&janet_vm.threaded_abstracts, 0);
|
||||||
janet_rng_seed(&janet_vm.ev_rng, 0);
|
janet_rng_seed(&janet_vm.ev_rng, 0);
|
||||||
|
#ifndef JANET_WINDOWS
|
||||||
|
pthread_attr_init(&janet_vm.new_thread_attr);
|
||||||
|
pthread_attr_setdetachstate(&janet_vm.new_thread_attr, PTHREAD_CREATE_DETACHED);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Common deinit code */
|
/* Common deinit code */
|
||||||
@ -566,6 +570,9 @@ void janet_ev_deinit_common(void) {
|
|||||||
janet_free(janet_vm.listeners);
|
janet_free(janet_vm.listeners);
|
||||||
janet_vm.listeners = NULL;
|
janet_vm.listeners = NULL;
|
||||||
janet_table_deinit(&janet_vm.threaded_abstracts);
|
janet_table_deinit(&janet_vm.threaded_abstracts);
|
||||||
|
#ifndef JANET_WINDOWS
|
||||||
|
pthread_attr_destroy(&janet_vm.new_thread_attr);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Short hand to yield to event loop */
|
/* Short hand to yield to event loop */
|
||||||
@ -2072,12 +2079,11 @@ void janet_ev_threaded_call(JanetThreadedSubroutine fp, JanetEVGenericMessage ar
|
|||||||
#else
|
#else
|
||||||
init->write_pipe = janet_vm.selfpipe[1];
|
init->write_pipe = janet_vm.selfpipe[1];
|
||||||
pthread_t waiter_thread;
|
pthread_t waiter_thread;
|
||||||
int err = pthread_create(&waiter_thread, NULL, janet_thread_body, init);
|
int err = pthread_create(&waiter_thread, &janet_vm.new_thread_attr, janet_thread_body, init);
|
||||||
if (err) {
|
if (err) {
|
||||||
janet_free(init);
|
janet_free(init);
|
||||||
janet_panicf("%s", strerror(err));
|
janet_panicf("%s", strerror(err));
|
||||||
}
|
}
|
||||||
pthread_detach(waiter_thread);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Increment ev refcount so we don't quit while waiting for a subprocess */
|
/* Increment ev refcount so we don't quit while waiting for a subprocess */
|
||||||
|
@ -152,16 +152,19 @@ struct JanetVM {
|
|||||||
#ifdef JANET_WINDOWS
|
#ifdef JANET_WINDOWS
|
||||||
void **iocp;
|
void **iocp;
|
||||||
#elif defined(JANET_EV_EPOLL)
|
#elif defined(JANET_EV_EPOLL)
|
||||||
|
pthread_attr_t new_thread_attr;
|
||||||
JanetHandle selfpipe[2];
|
JanetHandle selfpipe[2];
|
||||||
int epoll;
|
int epoll;
|
||||||
int timerfd;
|
int timerfd;
|
||||||
int timer_enabled;
|
int timer_enabled;
|
||||||
#elif defined(JANET_EV_KQUEUE)
|
#elif defined(JANET_EV_KQUEUE)
|
||||||
|
pthread_attr_t new_thread_attr;
|
||||||
JanetHandle selfpipe[2];
|
JanetHandle selfpipe[2];
|
||||||
int kq;
|
int kq;
|
||||||
int timer;
|
int timer;
|
||||||
int timer_enabled;
|
int timer_enabled;
|
||||||
#else
|
#else
|
||||||
|
pthread_attr_t new_thread_attr;
|
||||||
JanetHandle selfpipe[2];
|
JanetHandle selfpipe[2];
|
||||||
struct pollfd *fds;
|
struct pollfd *fds;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user