According to the PTHREAD_COND(3) man page, a condition variable
signaling and broadcast should alway be protected with a mutex.
This commit fixes two calls to `pthread_cond_signal()` function without
holding the right lock.
This commit also adds an assertion right before two calls to
`pthread_cond_broadcast()` where it's less obvious from the surrounding
code that the mutex is held. This documents the code and may be useful
for future debugging.
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Iebf5a8b2e4251bd1ff4cd462e548cd3486c6cb75
{
struct action_executor *executor = _data;
+ pthread_mutex_lock(&executor->work.lock);
executor->should_quit = true;
pthread_cond_signal(&executor->work.cond);
+ pthread_mutex_unlock(&executor->work.lock);
return true;
}
signal = true;
error_unlock:
- pthread_mutex_unlock(&executor->work.lock);
if (signal) {
pthread_cond_signal(&executor->work.cond);
}
+ pthread_mutex_unlock(&executor->work.lock);
lttng_evaluation_destroy(evaluation);
return executor_status;
* Broadcast after free-ing to ensure the memory is
* reclaimed before the main thread exits.
*/
+ ASSERT_LOCKED(ltt_session_list.lock);
pthread_cond_broadcast(<t_session_list.removal_cond);
}
}
static int signal_metadata(struct lttng_consumer_stream *stream,
struct lttng_consumer_local_data *ctx)
{
+ ASSERT_LOCKED(stream->metadata_rdv_lock);
return pthread_cond_broadcast(&stream->metadata_rdv) ? -errno : 0;
}