From: Jonathan Rajotte Date: Fri, 7 Aug 2020 19:39:24 +0000 (-0400) Subject: condition: introduce reference counting X-Git-Tag: v2.13.0-rc1~511 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=4655b864b310dca6b4346770351a0e6a261ba5a1;p=lttng-tools.git condition: introduce reference counting This will allows easier management of the trigger ownership of its associated condition and action objects. Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau Change-Id: I46420b03bd4bf7948bc2d1f44985edfe86c27c61 --- diff --git a/include/lttng/condition/condition-internal.h b/include/lttng/condition/condition-internal.h index 98a830942..405199b42 100644 --- a/include/lttng/condition/condition-internal.h +++ b/include/lttng/condition/condition-internal.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -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); diff --git a/src/common/condition.c b/src/common/condition.c index 367f4a38b..427c49e09 100644 --- a/src/common/condition.c +++ b/src/common/condition.c @@ -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); }