#ifndef LTTNG_TRIGGER_INTERNAL_H
#define LTTNG_TRIGGER_INTERNAL_H
-#include <lttng/trigger/trigger.h>
#include <common/credentials.h>
#include <common/dynamic-array.h>
#include <common/macros.h>
#include <common/optional.h>
-#include <stdint.h>
+#include <lttng/trigger/trigger.h>
+#include <pthread.h>
#include <stdbool.h>
+#include <stdint.h>
#include <sys/types.h>
#include <urcu/ref.h>
* notification.
*/
LTTNG_OPTIONAL(uint64_t) tracer_token;
+
+ /*
+ * Is the trigger registered?
+ *
+ * This is necessary since a reference holder might be interested in the
+ * overall state of the trigger from the point of view of its owner.
+ *
+ * The main user is the action executor since we want to prevent the
+ * execution of actions related to a trigger that is unregistered.
+ *
+ * Not considered for `is_equal`.
+ */
+ bool registered;
+
+ /*
+ * The lock is used to protect against concurrent trigger execution and
+ * trigger removal.
+ */
+ pthread_mutex_t lock;
};
struct lttng_triggers {
LTTNG_HIDDEN
bool lttng_trigger_needs_tracer_notifier(const struct lttng_trigger *trigger);
+LTTNG_HIDDEN
+void lttng_trigger_set_as_registered(struct lttng_trigger *trigger);
+
+LTTNG_HIDDEN
+void lttng_trigger_set_as_unregistered(struct lttng_trigger *trigger);
+
+/*
+ * The trigger must be locked before calling lttng_trigger_is_registered.
+ *
+ * The lock is necessary since a trigger can be unregistered at any time.
+ *
+ * Manipulations requiring that the trigger be registered must always acquire
+ * the trigger lock for the duration of the manipulation using
+ * `lttng_trigger_lock` and `lttng_trigger_unlock`.
+ */
+LTTNG_HIDDEN
+bool lttng_trigger_is_registered(struct lttng_trigger *trigger);
+
+LTTNG_HIDDEN
+void lttng_trigger_lock(struct lttng_trigger *trigger);
+
+LTTNG_HIDDEN
+void lttng_trigger_unlock(struct lttng_trigger *trigger);
+
#endif /* LTTNG_TRIGGER_INTERNAL_H */
goto error_free_ht_element;
}
+ /* From this point consider the trigger registered. */
+ lttng_trigger_set_as_registered(trigger);
+
/*
* Some triggers might need a tracer notifier depending on its
* condition and actions.
}
error:
if (free_trigger) {
+ /*
+ * Other objects might have a reference to the trigger, mark it
+ * as unregistered.
+ */
+ lttng_trigger_set_as_unregistered(trigger);
lttng_trigger_destroy(trigger);
}
end:
cmd_reply = LTTNG_OK;
}
+ trigger_ht_element = caa_container_of(triggers_ht_node,
+ struct lttng_trigger_ht_element, node);
+
+ /* From this point, consider the trigger unregistered no matter what. */
+ lttng_trigger_set_as_unregistered(trigger_ht_element->trigger);
+
/* Remove trigger from channel_triggers_ht. */
cds_lfht_for_each_entry(state->channel_triggers_ht, &iter, trigger_list,
channel_triggers_ht_node) {
teardown_tracer_notifier(state, trigger);
}
- trigger_ht_element = caa_container_of(triggers_ht_node,
- struct lttng_trigger_ht_element, node);
-
if (is_trigger_action_notify(trigger)) {
/*
* Remove and release the client list from
*
*/
-#include <lttng/trigger/trigger-internal.h>
-#include <lttng/condition/condition-internal.h>
-#include <lttng/condition/on-event-internal.h>
-#include <lttng/condition/on-event.h>
-#include <lttng/condition/on-event-internal.h>
-#include <lttng/condition/buffer-usage.h>
-#include <lttng/event-rule/event-rule-internal.h>
-#include <lttng/event-expr-internal.h>
-#include <lttng/action/action-internal.h>
+#include <assert.h>
#include <common/credentials.h>
-#include <common/payload.h>
-#include <common/payload-view.h>
-#include <lttng/domain.h>
-#include <common/error.h>
#include <common/dynamic-array.h>
+#include <common/error.h>
#include <common/optional.h>
-#include <assert.h>
+#include <common/payload-view.h>
+#include <common/payload.h>
#include <inttypes.h>
+#include <lttng/action/action-internal.h>
+#include <lttng/condition/buffer-usage.h>
+#include <lttng/condition/condition-internal.h>
+#include <lttng/condition/on-event-internal.h>
+#include <lttng/condition/on-event.h>
+#include <lttng/domain.h>
+#include <lttng/event-expr-internal.h>
+#include <lttng/event-rule/event-rule-internal.h>
+#include <lttng/trigger/trigger-internal.h>
+#include <pthread.h>
LTTNG_HIDDEN
bool lttng_trigger_validate(const struct lttng_trigger *trigger)
lttng_action_get(action);
trigger->action = action;
+ pthread_mutex_init(&trigger->lock, NULL);
+ trigger->registered = false;
+
end:
return trigger;
}
lttng_action_put(action);
lttng_condition_put(condition);
+ pthread_mutex_destroy(&trigger->lock);
+
free(trigger->name);
free(trigger);
}
end:
return needs_tracer_notifier;
}
+
+LTTNG_HIDDEN
+void lttng_trigger_set_as_registered(struct lttng_trigger *trigger)
+{
+ pthread_mutex_lock(&trigger->lock);
+ trigger->registered = true;
+ pthread_mutex_unlock(&trigger->lock);
+}
+
+LTTNG_HIDDEN
+void lttng_trigger_set_as_unregistered(struct lttng_trigger *trigger)
+{
+ pthread_mutex_lock(&trigger->lock);
+ trigger->registered = false;
+ pthread_mutex_unlock(&trigger->lock);
+}
+
+/*
+ * The trigger must be locked before calling lttng_trigger_registered.
+ * The lock is necessary since a trigger can be unregistered at anytime.
+ * Manipulations requiring that the trigger be registered must always acquire
+ * the trigger lock for the duration of the manipulation using
+ * `lttng_trigger_lock` and `lttng_trigger_unlock`.
+ */
+LTTNG_HIDDEN
+bool lttng_trigger_is_registered(struct lttng_trigger *trigger)
+{
+ ASSERT_LOCKED(trigger->lock);
+ return trigger->registered;
+}
+
+LTTNG_HIDDEN
+void lttng_trigger_lock(struct lttng_trigger *trigger)
+{
+ pthread_mutex_lock(&trigger->lock);
+}
+
+LTTNG_HIDDEN
+void lttng_trigger_unlock(struct lttng_trigger *trigger)
+{
+ pthread_mutex_unlock(&trigger->lock);
+}