From f5eeb9d734eb6727a2ee04f08e3eedf9827ed66f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 3 Apr 2018 12:11:24 -0400 Subject: [PATCH] Simplify lock handling in enqueue_timer_rotate_job() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/sessiond-timer.c | 38 ++++++++++--------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/src/bin/lttng-sessiond/sessiond-timer.c b/src/bin/lttng-sessiond/sessiond-timer.c index 0d500aa55..ba8373bb9 100644 --- a/src/bin/lttng-sessiond/sessiond-timer.c +++ b/src/bin/lttng-sessiond/sessiond-timer.c @@ -284,35 +284,29 @@ int enqueue_timer_rotate_job(struct timer_thread_parameters *ctx, struct ltt_session *session, unsigned int signal) { int ret; - bool has_duplicate_timer_job; char *c = "!"; + struct sessiond_rotation_timer *timer_data = NULL; pthread_mutex_lock(&ctx->rotation_timer_queue->lock); - has_duplicate_timer_job = check_duplicate_timer_job(ctx, session, - signal); - - if (!has_duplicate_timer_job) { - struct sessiond_rotation_timer *timer_data = NULL; - - timer_data = zmalloc(sizeof(struct sessiond_rotation_timer)); - if (!timer_data) { - PERROR("Allocation of timer data"); - goto error; - } - timer_data->session_id = session->id; - timer_data->signal = signal; - cds_list_add_tail(&timer_data->head, - &ctx->rotation_timer_queue->list); - } else { + if (check_duplicate_timer_job(ctx, session, signal)) { /* * This timer job is already pending, we don't need to add * it. */ - pthread_mutex_unlock(&ctx->rotation_timer_queue->lock); ret = 0; goto end; } - pthread_mutex_unlock(&ctx->rotation_timer_queue->lock); + + timer_data = zmalloc(sizeof(struct sessiond_rotation_timer)); + if (!timer_data) { + PERROR("Allocation of timer data"); + ret = -1; + goto end; + } + timer_data->session_id = session->id; + timer_data->signal = signal; + cds_list_add_tail(&timer_data->head, + &ctx->rotation_timer_queue->list); ret = lttng_write( lttng_pipe_get_writefd(ctx->rotation_timer_queue->event_pipe), @@ -328,15 +322,13 @@ int enqueue_timer_rotate_job(struct timer_thread_parameters *ctx, goto end; } PERROR("Timer wakeup rotation thread"); - goto error; + goto end; } ret = 0; - goto end; -error: - ret = -1; end: + pthread_mutex_unlock(&ctx->rotation_timer_queue->lock); return ret; } -- 2.34.1