From 62d1ec3f8a351d906842f772d92305ab506649fd Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 26 Apr 2015 17:47:23 +1000 Subject: [PATCH] Use signal handlers from sender and receiver threads in the connector avoid needing to pthread tryjoin on every message --- src/ckpool.c | 4 +--- src/ckpool.h | 1 + src/connector.c | 25 +++++++------------------ 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index 4bd99f22..9b9396e6 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -202,8 +202,6 @@ bool ckmsgq_empty(ckmsgq_t *ckmsgq) return ret; } -static void childsighandler(const int sig); - /* Create a standalone thread that queues received unix messages for a proc * instance and adds them to linked list of received messages with their * associated receive socket, then signal the associated rmsg_cond for the @@ -879,7 +877,7 @@ static void rm_namepid(const proc_instance_t *pi) /* Disable signal handlers for child processes, but simply pass them onto the * parent process to shut down cleanly. */ -static void childsighandler(const int sig) +void childsighandler(const int sig) { signal(sig, SIG_IGN); signal(SIGTERM, SIG_IGN); diff --git a/src/ckpool.h b/src/ckpool.h index 2388aedd..656fc5fa 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -255,6 +255,7 @@ char *_ckdb_msg_call(const ckpool_t *ckp, const char *msg, const char *file, co json_t *json_rpc_call(connsock_t *cs, const char *rpc_req); +void childsighandler(const int sig); int process_exit(ckpool_t *ckp, const proc_instance_t *pi, int ret); bool json_get_string(char **store, const json_t *val, const char *res); bool json_get_int64(int64_t *store, const json_t *val, const char *res); diff --git a/src/connector.c b/src/connector.c index 38052a23..6e469e29 100644 --- a/src/connector.c +++ b/src/connector.c @@ -450,7 +450,7 @@ void *receiver(void *arg) epfd = cdata->epfd = epoll_create1(EPOLL_CLOEXEC); if (epfd < 0) { LOGEMERG("FATAL: Failed to create epoll in receiver"); - return NULL; + goto out; } serverfds = cdata->ckp->serverurls; /* Add all the serverfds to the epoll */ @@ -461,7 +461,7 @@ void *receiver(void *arg) ret = epoll_ctl(epfd, EPOLL_CTL_ADD, cdata->serverfd[i], &event); if (ret < 0) { LOGEMERG("FATAL: Failed to add epfd %d to epoll_ctl", epfd); - return NULL; + goto out; } } @@ -541,6 +541,9 @@ void *receiver(void *arg) noparse: dec_instance_ref(cdata, client); } +out: + /* We shouldn't get here unless there's an error */ + childsighandler(15); return NULL; } @@ -641,7 +644,8 @@ contfree: free(sender_send); dec_instance_ref(cdata, client); } - + /* We shouldn't get here unless there's an error */ + childsighandler(15); return NULL; } @@ -804,7 +808,6 @@ static int connector_loop(proc_instance_t *pi, cdata_t *cdata) { unix_msg_t *umsg = NULL; ckpool_t *ckp = pi->ckp; - uint8_t test_cycle = 0; int64_t client_id; char *buf; int ret = 0; @@ -818,20 +821,6 @@ retry: dealloc(umsg); } - if (!++test_cycle) { - /* Test for pthread join every 256 messages */ - if (unlikely(!pthread_tryjoin_np(cdata->pth_sender, NULL))) { - LOGEMERG("Connector sender thread shutdown, exiting"); - ret = 1; - goto out; - } - if (unlikely(!pthread_tryjoin_np(cdata->pth_receiver, NULL))) { - LOGEMERG("Connector receiver thread shutdown, exiting"); - ret = 1; - goto out; - } - } - do { umsg = get_unix_msg(pi); } while (!umsg);