diff --git a/src/pipe.c b/src/pipe.c index eb93e5428..2931907ab 100644 --- a/src/pipe.c +++ b/src/pipe.c @@ -49,7 +49,6 @@ struct dir { struct pool pool; pthread_t thread; bool enabled; - bool started; } sendd, recvv; bool reverse = false; @@ -60,13 +59,13 @@ pthread_t ptid; /**< Parent thread id */ static void quit(int signal, siginfo_t *sinfo, void *ctx) { - if (recvv.started) { + if (recvv.enabled) { pthread_cancel(recvv.thread); pthread_join(recvv.thread, NULL); pool_destroy(&recvv.pool); } - if (sendd.started) { + if (sendd.enabled) { pthread_cancel(sendd.thread); pthread_join(sendd.thread, NULL); pool_destroy(&sendd.pool); @@ -105,11 +104,6 @@ static void * send_loop(void *ctx) int ret; struct sample *smps[node->vectorize]; - if (!sendd.enabled) - return NULL; - - sendd.started = true; - /* Initialize memory */ ret = pool_init(&sendd.pool, LOG2_CEIL(node->vectorize), SAMPLE_LEN(DEFAULT_SAMPLELEN), &memtype_hugepage); if (ret < 0) @@ -152,11 +146,6 @@ static void * recv_loop(void *ctx) int ret; struct sample *smps[node->vectorize]; - if (!recvv.enabled) - return NULL; - - recvv.started = true; - /* Initialize memory */ ret = pool_init(&recvv.pool, LOG2_CEIL(node->vectorize), SAMPLE_LEN(DEFAULT_SAMPLELEN), &memtype_hugepage); if (ret < 0) @@ -264,8 +253,11 @@ int main(int argc, char *argv[]) error("Failed to start node: %s", node_name(node)); /* Start threads */ - pthread_create(&recvv.thread, NULL, recv_loop, NULL); - pthread_create(&sendd.thread, NULL, send_loop, NULL); + if (recvv.enabled) + pthread_create(&recvv.thread, NULL, recv_loop, NULL); + + if (sendd.enabled) + pthread_create(&sendd.thread, NULL, send_loop, NULL); for (;;) sleep(1);