From: Mathieu Desnoyers Date: Fri, 16 Jun 2017 21:23:12 +0000 (-0400) Subject: Cleanup: use CMM accessors for consumer_quit variable X-Git-Tag: v2.11.0-rc1~520 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=10211f5c32e51e398cb37508851956a2f8b7dbbf;p=lttng-tools.git Cleanup: use CMM accessors for consumer_quit variable 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 --- 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