Merge duplicate code in consumer for destroy relayd
[lttng-tools.git] / src / common / consumer.c
index 363fa4eda6c5ba0dc75296d4c9f7d764c80b21da..2ee6c331318a844f675013b691a30e4fc34079f5 100644 (file)
@@ -201,6 +201,25 @@ void consumer_destroy_relayd(struct consumer_relayd_sock_pair *relayd)
        call_rcu(&relayd->node.head, consumer_rcu_free_relayd);
 }
 
+/*
+ * Flag a relayd socket pair for destruction. Destroy it if the refcount
+ * reaches zero.
+ *
+ * RCU read side lock MUST be aquired before calling this function.
+ */
+void consumer_flag_relayd_for_destroy(struct consumer_relayd_sock_pair *relayd)
+{
+       assert(relayd);
+
+       /* Set destroy flag for this object */
+       uatomic_set(&relayd->destroy_flag, 1);
+
+       /* Destroy the relayd if refcount is 0 */
+       if (uatomic_read(&relayd->refcount) == 0) {
+               consumer_destroy_relayd(relayd);
+       }
+}
+
 /*
  * Remove a stream from the global list protected by a mutex. This
  * function is also responsible for freeing its data structures.
This page took 0.023118 seconds and 4 git commands to generate.