From: Jonathan Rajotte Date: Fri, 7 Feb 2020 22:40:46 +0000 (-0500) Subject: trigger: introduce refcounting X-Git-Tag: v2.13.0-rc1~509 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=f01d28b41fb941aee87aaf70ed42a5928c784ba6;p=lttng-tools.git trigger: introduce refcounting Will be used for listing and much more use. Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau Change-Id: Ic9ee8753257fcbe15fc1321b18582628328c0154 --- diff --git a/include/lttng/trigger/trigger-internal.h b/include/lttng/trigger/trigger-internal.h index d857ff78e..4b031137c 100644 --- a/include/lttng/trigger/trigger-internal.h +++ b/include/lttng/trigger/trigger-internal.h @@ -15,11 +15,15 @@ #include #include #include +#include struct lttng_payload; struct lttng_payload_view; struct lttng_trigger { + /* Reference counting is only exposed to internal users. */ + struct urcu_ref ref; + struct lttng_condition *condition; struct lttng_action *action; LTTNG_OPTIONAL(struct lttng_credentials) creds; @@ -51,6 +55,12 @@ const struct lttng_action *lttng_trigger_get_const_action( LTTNG_HIDDEN bool lttng_trigger_validate(struct lttng_trigger *trigger); +LTTNG_HIDDEN +void lttng_trigger_get(struct lttng_trigger *trigger); + +LTTNG_HIDDEN +void lttng_trigger_put(struct lttng_trigger *trigger); + LTTNG_HIDDEN const struct lttng_credentials *lttng_trigger_get_credentials( const struct lttng_trigger *trigger); diff --git a/src/common/trigger.c b/src/common/trigger.c index 2ccf00735..2ef77b236 100644 --- a/src/common/trigger.c +++ b/src/common/trigger.c @@ -46,6 +46,8 @@ struct lttng_trigger *lttng_trigger_create( goto end; } + urcu_ref_init(&trigger->ref); + lttng_condition_get(condition); trigger->condition = condition; @@ -93,16 +95,14 @@ const struct lttng_action *lttng_trigger_get_const_action( return trigger->action; } -void lttng_trigger_destroy(struct lttng_trigger *trigger) +static void trigger_destroy_ref(struct urcu_ref *ref) { + struct lttng_trigger *trigger = + container_of(ref, struct lttng_trigger, ref); struct lttng_action *action = lttng_trigger_get_action(trigger); struct lttng_condition *condition = lttng_trigger_get_condition(trigger); - if (!trigger) { - return; - } - assert(action); assert(condition); @@ -113,6 +113,11 @@ void lttng_trigger_destroy(struct lttng_trigger *trigger) free(trigger); } +void lttng_trigger_destroy(struct lttng_trigger *trigger) +{ + lttng_trigger_put(trigger); +} + LTTNG_HIDDEN ssize_t lttng_trigger_create_from_payload( struct lttng_payload_view *src_view, @@ -231,6 +236,22 @@ end: return ret; } +LTTNG_HIDDEN +void lttng_trigger_get(struct lttng_trigger *trigger) +{ + urcu_ref_get(&trigger->ref); +} + +LTTNG_HIDDEN +void lttng_trigger_put(struct lttng_trigger *trigger) +{ + if (!trigger) { + return; + } + + urcu_ref_put(&trigger->ref , trigger_destroy_ref); +} + LTTNG_HIDDEN const struct lttng_credentials *lttng_trigger_get_credentials( const struct lttng_trigger *trigger)