condition: introduce reference counting
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 7 Aug 2020 19:39:24 +0000 (15:39 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 11 Aug 2020 17:43:33 +0000 (13:43 -0400)
This will allows easier management of the trigger ownership of its associated
condition and action objects.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I46420b03bd4bf7948bc2d1f44985edfe86c27c61

include/lttng/condition/condition-internal.h
src/common/condition.c

index 98a8309421684aa6d607ceb51834d0ed09743875..405199b428fcae3004e3b5fdb97caaaf9e993b86 100644 (file)
@@ -14,6 +14,7 @@
 #include <common/payload.h>
 #include <stdbool.h>
 #include <urcu/list.h>
+#include <urcu/ref.h>
 #include <stdint.h>
 #include <sys/types.h>
 
@@ -29,6 +30,8 @@ typedef ssize_t (*condition_create_from_payload_cb)(
                struct lttng_condition **condition);
 
 struct lttng_condition {
+       /* Reference counting is only exposed to internal users. */
+       struct urcu_ref ref;
        enum lttng_condition_type type;
        condition_validate_cb validate;
        condition_serialize_cb serialize;
@@ -42,6 +45,12 @@ struct lttng_condition_comm {
        char payload[];
 };
 
+LTTNG_HIDDEN
+void lttng_condition_get(struct lttng_condition *condition);
+
+LTTNG_HIDDEN
+void lttng_condition_put(struct lttng_condition *condition);
+
 LTTNG_HIDDEN
 void lttng_condition_init(struct lttng_condition *condition,
                enum lttng_condition_type type);
index 367f4a38b6b977045c3e97a7572d9e607f462ef8..427c49e093ec3c4621161d32f94eefba730e7bf7 100644 (file)
@@ -23,15 +23,36 @@ enum lttng_condition_type lttng_condition_get_type(
 }
 
 void lttng_condition_destroy(struct lttng_condition *condition)
+{
+       lttng_condition_put(condition);
+}
+
+static void condition_destroy_ref(struct urcu_ref *ref)
+{
+       struct lttng_condition *condition =
+               container_of(ref, struct lttng_condition, ref);
+
+       condition->destroy(condition);
+}
+
+LTTNG_HIDDEN
+void lttng_condition_get(struct lttng_condition *condition)
+{
+       urcu_ref_get(&condition->ref);
+}
+
+LTTNG_HIDDEN
+void lttng_condition_put(struct lttng_condition *condition)
 {
        if (!condition) {
                return;
        }
 
        assert(condition->destroy);
-       condition->destroy(condition);
+       urcu_ref_put(&condition->ref, condition_destroy_ref);
 }
 
+
 LTTNG_HIDDEN
 bool lttng_condition_validate(const struct lttng_condition *condition)
 {
@@ -171,4 +192,5 @@ void lttng_condition_init(struct lttng_condition *condition,
                enum lttng_condition_type type)
 {
        condition->type = type;
+       urcu_ref_init(&condition->ref);
 }
This page took 0.029367 seconds and 4 git commands to generate.