[lttng-dev] [PATCH lttng-tools 1/2] Cleanup: use CMM accessors for consumer_quit variable
Jérémie Galarneau
jeremie.galarneau at efficios.com
Wed Jun 21 12:25:32 UTC 2017
The first patch has been merged in master and stable-2.10. The second
one has been merged in master, stable-2.10, stable-2.9, and
stable-2.8.
Thanks!
Jérémie
On 16 June 2017 at 17:23, Mathieu Desnoyers
<mathieu.desnoyers at efficios.com> wrote:
> 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 <mathieu.desnoyers at efficios.com>
> ---
> 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 d07e5b4..9834322 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 7375373..220dbb4 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 b5afc73..8d00a0d 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 99803a6..4297d60 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.1.4
>
--
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com
More information about the lttng-dev
mailing list