diff --git a/src/lib/mpmc.c b/src/lib/mpmc.c index 66ff678..80ba088 100644 --- a/src/lib/mpmc.c +++ b/src/lib/mpmc.c @@ -8,11 +8,6 @@ #include #include -typedef struct { - mpmc_t *ctx; - int worker_id; -} mpmc_arg_t; - static void *mpmc_worker(void *arg); int mpmc_init(mpmc_t *ctx, int n_workers, int buf_size, void (*consumer)(void *obj), const char *name) { @@ -40,8 +35,8 @@ int mpmc_init(mpmc_t *ctx, int n_workers, int buf_size, void (*consumer)(void *o return -1; } - memset(ctx->buffer, 0, ctx->size * sizeof(void *)); - memset(ctx->workers, 0, ctx->n_workers * sizeof(pthread_t)); + memset(ctx->buffer, 0, ctx->size * sizeof(void *)); + memset(ctx->workers, -1, ctx->n_workers * sizeof(pthread_t)); for (int i = 0; i < ctx->n_workers; i++) { int ret; @@ -155,11 +150,9 @@ void mpmc_destroy(mpmc_t *ctx) { // stop threads, if running mpmc_stop(ctx); for (int i = 0; i < ctx->n_workers; i++) { - if (ctx->workers[i] == 0) break; - // FIXME + if (ctx->workers[i] == -1) break; pthread_kill(ctx->workers[i], SIGUSR1); - //pthread_join(ctx->workers[i], NULL); - pthread_cancel(ctx->workers[i]); + pthread_join(ctx->workers[i], NULL); } sem_destroy(&ctx->free); diff --git a/src/server.c b/src/server.c index f71a032..2e7a452 100644 --- a/src/server.c +++ b/src/server.c @@ -125,8 +125,10 @@ static void terminate_gracefully(int sig) { notice("Terminating gracefully..."); server_alive = 0; - signal(SIGINT, terminate_forcefully); - signal(SIGTERM, terminate_forcefully); + struct sigaction act = {0}; + act.sa_handler = terminate_forcefully; + sigaction(SIGINT, &act, NULL); + sigaction(SIGTERM, &act, NULL); workers_stop(); workers_destroy(); @@ -225,10 +227,13 @@ int main(int argc, char *const argv[]) { return 1; } - signal(SIGINT, terminate_gracefully); - signal(SIGTERM, terminate_gracefully); - signal(SIGUSR1, nothing); - signal(SIGPIPE, nothing); + struct sigaction act = {0}; + act.sa_handler = terminate_gracefully; + sigaction(SIGINT, &act, NULL); + sigaction(SIGTERM, &act, NULL); + act.sa_handler = nothing; + sigaction(SIGUSR1, &act, NULL); + sigaction(SIGPIPE, &act, NULL); if ((ret = geoip_init(config.geoip_dir)) != 0) { if (ret == -1) {