*
* Please see session.h for more explanation and correct usage of the list.
*/
-struct ltt_session_list the_session_list = {
- .lock = PTHREAD_MUTEX_INITIALIZER,
- .removal_cond = PTHREAD_COND_INITIALIZER,
- .next_uuid = 0,
- .head = CDS_LIST_HEAD_INIT(the_session_list.head),
-};
+struct ltt_session_list the_session_list;
} /* namespace */
/*
*/
void session_list_wait_empty()
{
- pthread_mutex_lock(&the_session_list.lock);
- while (!cds_list_empty(&the_session_list.head)) {
- pthread_cond_wait(&the_session_list.removal_cond, &the_session_list.lock);
- }
- pthread_mutex_unlock(&the_session_list.lock);
+ std::unique_lock<std::mutex> list_lock(the_session_list.lock);
+
+ /* Keep waiting until the session list is empty. */
+ the_session_list.removal_cond.wait(list_lock,
+ [] { return cds_list_empty(&the_session_list.head); });
}
/*
*/
void session_lock_list() noexcept
{
- pthread_mutex_lock(&the_session_list.lock);
+ the_session_list.lock.lock();
}
/*
*/
int session_trylock_list() noexcept
{
- return pthread_mutex_trylock(&the_session_list.lock);
+ /* Return 0 if successfully acquired. */
+ return the_session_list.lock.try_lock() ? 0 : 1;
}
/*
*/
void session_unlock_list() noexcept
{
- pthread_mutex_unlock(&the_session_list.lock);
+ the_session_list.lock.unlock();
}
/*
pthread_mutex_destroy(&session->lock);
if (session_published) {
- ASSERT_LOCKED(the_session_list.lock);
+ ASSERT_SESSION_LIST_LOCKED();
del_session_list(session);
del_session_ht(session);
}
free(session);
if (session_published) {
/*
- * Broadcast after free-ing to ensure the memory is
- * reclaimed before the main thread exits.
+ * Notify after free-ing to ensure the memory is
+ * reclaimed before the main thread exits (and prevent memory leak
+ * reports).
*/
- ASSERT_LOCKED(the_session_list.lock);
- pthread_cond_broadcast(&the_session_list.removal_cond);
+ ASSERT_SESSION_LIST_LOCKED();
+ the_session_list.removal_cond.notify_all();
}
}
* The session list lock must be held as any session_put()
* may cause the removal of the session from the session_list.
*/
- ASSERT_LOCKED(the_session_list.lock);
+ ASSERT_SESSION_LIST_LOCKED();
LTTNG_ASSERT(session->ref.refcount);
urcu_ref_put(&session->ref, session_release);
}
struct ltt_session *iter;
LTTNG_ASSERT(name);
- ASSERT_LOCKED(the_session_list.lock);
+ ASSERT_SESSION_LIST_LOCKED();
DBG2("Trying to find session by name %s", name);
struct ltt_session *ls;
ASSERT_RCU_READ_LOCKED();
- ASSERT_LOCKED(the_session_list.lock);
+ ASSERT_SESSION_LIST_LOCKED();
if (!ltt_sessions_ht_by_id) {
goto end;
enum lttng_error_code ret_code;
struct ltt_session *new_session = nullptr;
- ASSERT_LOCKED(the_session_list.lock);
+ ASSERT_SESSION_LIST_LOCKED();
if (name) {
struct ltt_session *clashing_session;
{
int ret = 0;
- ASSERT_LOCKED(the_session_list.lock);
+ ASSERT_SESSION_LIST_LOCKED();
ASSERT_LOCKED(session.lock);
session.rotation_state = result;
#include <lttng/lttng-error.h>
#include <lttng/rotation.h>
+#include <condition_variable>
#include <limits.h>
+#include <mutex>
#include <stdbool.h>
#include <urcu/list.h>
* functions are used, the lock MUST be acquired in order to
* iterate or/and do any actions on that list.
*/
- pthread_mutex_t lock;
+ std::mutex lock;
/*
* This condition variable is signaled on every removal from
* the session list.
*/
- pthread_cond_t removal_cond;
+ std::condition_variable removal_cond;
/*
* Session unique ID generator. The session list lock MUST be
* upon update and read of this counter.
*/
- uint64_t next_uuid;
+ uint64_t next_uuid = 0;
/* Linked list head */
- struct cds_list_head head;
+ struct cds_list_head head = CDS_LIST_HEAD_INIT(head);
};
/*