X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-relayd%2Fctf-trace.cpp;h=cad67b78e2517296f06e3610b2d7b3d7e25d2ce2;hb=64803277bbdbe0a943360d918298a48157d9da55;hp=7a3cbdea0ebde00f0613ccff1cb42553d2d6d798;hpb=ac497a37018f3c253d2e50397294f58d33f7f24f;p=lttng-tools.git diff --git a/src/bin/lttng-relayd/ctf-trace.cpp b/src/bin/lttng-relayd/ctf-trace.cpp index 7a3cbdea0..cad67b78e 100644 --- a/src/bin/lttng-relayd/ctf-trace.cpp +++ b/src/bin/lttng-relayd/ctf-trace.cpp @@ -9,13 +9,13 @@ #define _LGPL_SOURCE -#include -#include +#include +#include #include -#include "ctf-trace.h" -#include "lttng-relayd.h" -#include "stream.h" +#include "ctf-trace.hpp" +#include "lttng-relayd.hpp" +#include "stream.hpp" static uint64_t last_relay_ctf_trace_id; static pthread_mutex_t last_relay_ctf_trace_id_lock = PTHREAD_MUTEX_INITIALIZER; @@ -41,6 +41,8 @@ static void ctf_trace_destroy(struct ctf_trace *trace) * control side. */ LTTNG_ASSERT(cds_list_empty(&trace->stream_list)); + ASSERT_RCU_READ_LOCKED(); + session_put(trace->session); trace->session = NULL; free(trace->path); @@ -62,11 +64,26 @@ static void ctf_trace_release(struct urcu_ref *ref) } /* - * Should be called with RCU read-side lock held. + * The caller must either: + * - hold the RCU read side lock, or + * - guarantee the existence of the object by already holding a reference to + * the object. */ bool ctf_trace_get(struct ctf_trace *trace) { - return urcu_ref_get_unless_zero(&trace->ref); + const bool ref = urcu_ref_get_unless_zero(&trace->ref); + + if (!ref) { + /* + * The ref count is already zero. It means the object is being + * torn down concurently. + * This is only acceptable if we hold the RCU read-side lock, + * else it's a logic error. + */ + ASSERT_RCU_READ_LOCKED(); + } + + return ref; } /* @@ -80,7 +97,7 @@ static struct ctf_trace *ctf_trace_create(struct relay_session *session, { struct ctf_trace *trace; - trace = (ctf_trace *) zmalloc(sizeof(*trace)); + trace = zmalloc(); if (!trace) { PERROR("Failed to allocate ctf_trace"); goto end;