From 10211f5c32e51e398cb37508851956a2f8b7dbbf Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Fri, 16 Jun 2017 17:23:12 -0400 Subject: [PATCH 1/1] Cleanup: use CMM accessors for consumer_quit variable MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Use CMM_LOAD_SHARED and CMM_STORE_SHARED, which are strictly equivalent to a volatile variable, in line with the rest of the lttng-tools project. Also move its declaration to a header, rather than having multiple declarations in C files, now following our coding style. Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- src/common/consumer/consumer.c | 10 +++++----- src/common/consumer/consumer.h | 6 ++++++ src/common/kernel-consumer/kernel-consumer.c | 1 - src/common/ust-consumer/ust-consumer.c | 1 - 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/common/consumer/consumer.c b/src/common/consumer/consumer.c index d07e5b492..9834322cf 100644 --- a/src/common/consumer/consumer.c +++ b/src/common/consumer/consumer.c @@ -76,7 +76,7 @@ int data_consumption_paused; * Also updated by the signal handler (consumer_should_exit()). Read by the * polling threads. */ -volatile int consumer_quit; +int consumer_quit; /* * Global hash table containing respectively metadata and data streams. The @@ -1227,7 +1227,7 @@ void lttng_consumer_should_exit(struct lttng_consumer_local_data *ctx) { ssize_t ret; - consumer_quit = 1; + CMM_STORE_SHARED(consumer_quit, 1); ret = lttng_write(ctx->consumer_should_quit[1], "4", 1); if (ret < 1) { PERROR("write consumer quit"); @@ -2526,7 +2526,7 @@ void *consumer_thread_data_poll(void *data) pthread_mutex_unlock(&consumer_data.lock); /* No FDs and consumer_quit, consumer_cleanup the thread */ - if (nb_fd == 0 && consumer_quit == 1) { + if (nb_fd == 0 && CMM_LOAD_SHARED(consumer_quit) == 1) { err = 0; /* All is OK */ goto end; } @@ -3203,7 +3203,7 @@ void *consumer_thread_sessiond_poll(void *data) err = 0; goto end; } - if (consumer_quit) { + if (CMM_LOAD_SHARED(consumer_quit)) { DBG("consumer_thread_receive_fds received quit from signal"); err = 0; /* All is OK */ goto end; @@ -3228,7 +3228,7 @@ end: * when all fds have hung up, the polling thread * can exit cleanly */ - consumer_quit = 1; + CMM_STORE_SHARED(consumer_quit, 1); /* * Notify the data poll thread to poll back again and test the diff --git a/src/common/consumer/consumer.h b/src/common/consumer/consumer.h index 7375373c7..220dbb4a2 100644 --- a/src/common/consumer/consumer.h +++ b/src/common/consumer/consumer.h @@ -604,6 +604,12 @@ struct lttng_consumer_global_data { struct lttng_ht *stream_per_chan_id_ht; }; +/* + * Set to nonzero when the consumer is exiting. Updated by signal + * handler and thread exit, read by threads. + */ +extern int consumer_quit; + /* Flag used to temporarily pause data consumption from testpoints. */ extern int data_consumption_paused; diff --git a/src/common/kernel-consumer/kernel-consumer.c b/src/common/kernel-consumer/kernel-consumer.c index b5afc73aa..8d00a0d46 100644 --- a/src/common/kernel-consumer/kernel-consumer.c +++ b/src/common/kernel-consumer/kernel-consumer.c @@ -48,7 +48,6 @@ extern struct lttng_consumer_global_data consumer_data; extern int consumer_poll_timeout; -extern volatile int consumer_quit; /* * Take a snapshot for a specific fd diff --git a/src/common/ust-consumer/ust-consumer.c b/src/common/ust-consumer/ust-consumer.c index 99803a693..4297d60cf 100644 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.c @@ -51,7 +51,6 @@ extern struct lttng_consumer_global_data consumer_data; extern int consumer_poll_timeout; -extern volatile int consumer_quit; /* * Free channel object and all streams associated with it. This MUST be used -- 2.34.1