Add hash table argument to helper functions
[lttng-tools.git] / src / common / consumer.c
index f01eb5d065dd2d81dff1089754014fd449a8a10c..161bf7e324ba38abcc6976f91f219c9f2257d4af 100644 (file)
@@ -62,12 +62,15 @@ volatile int consumer_quit = 0;
  * Find a stream. The consumer_data.lock must be locked during this
  * call.
  */
-static struct lttng_consumer_stream *consumer_find_stream(int key)
+static struct lttng_consumer_stream *consumer_find_stream(int key,
+               struct lttng_ht *ht)
 {
        struct lttng_ht_iter iter;
        struct lttng_ht_node_ulong *node;
        struct lttng_consumer_stream *stream = NULL;
 
+       assert(ht);
+
        /* Negative keys are lookup failures */
        if (key < 0) {
                return NULL;
@@ -75,8 +78,7 @@ static struct lttng_consumer_stream *consumer_find_stream(int key)
 
        rcu_read_lock();
 
-       lttng_ht_lookup(consumer_data.stream_ht, (void *)((unsigned long) key),
-                       &iter);
+       lttng_ht_lookup(ht, (void *)((unsigned long) key), &iter);
        node = lttng_ht_iter_get_node_ulong(&iter);
        if (node != NULL) {
                stream = caa_container_of(node, struct lttng_consumer_stream, node);
@@ -87,12 +89,12 @@ static struct lttng_consumer_stream *consumer_find_stream(int key)
        return stream;
 }
 
-static void consumer_steal_stream_key(int key)
+static void consumer_steal_stream_key(int key, struct lttng_ht *ht)
 {
        struct lttng_consumer_stream *stream;
 
        rcu_read_lock();
-       stream = consumer_find_stream(key);
+       stream = consumer_find_stream(key, ht);
        if (stream) {
                stream->key = -1;
                /*
@@ -443,7 +445,7 @@ int consumer_add_stream(struct lttng_consumer_stream *stream)
 
        pthread_mutex_lock(&consumer_data.lock);
        /* Steal stream identifier, for UST */
-       consumer_steal_stream_key(stream->key);
+       consumer_steal_stream_key(stream->key, consumer_data.stream_ht);
 
        rcu_read_lock();
        lttng_ht_lookup(consumer_data.stream_ht,
@@ -620,7 +622,7 @@ void consumer_change_stream_state(int stream_key,
        struct lttng_consumer_stream *stream;
 
        pthread_mutex_lock(&consumer_data.lock);
-       stream = consumer_find_stream(stream_key);
+       stream = consumer_find_stream(stream_key, consumer_data.stream_ht);
        if (stream) {
                stream->state = state;
        }
@@ -1516,9 +1518,7 @@ int lttng_consumer_recv_cmd(struct lttng_consumer_local_data *ctx,
 }
 
 /*
- * Iterate over all stream element of the hashtable and free them. This is race
- * free since the hashtable received MUST be in a race free synchronization
- * state. It's the caller responsability to make sure of that.
+ * Iterate over all streams of the hashtable and free them properly.
  */
 static void destroy_stream_ht(struct lttng_ht *ht)
 {
@@ -1535,7 +1535,7 @@ static void destroy_stream_ht(struct lttng_ht *ht)
                ret = lttng_ht_del(ht, &iter);
                assert(!ret);
 
-               free(stream);
+               call_rcu(&stream->node.head, consumer_free_stream);
        }
        rcu_read_unlock();
 
@@ -1635,7 +1635,7 @@ static void consumer_del_metadata_stream(struct lttng_consumer_stream *stream)
                consumer_del_channel(stream->chan);
        }
 
-       free(stream);
+       call_rcu(&stream->node.head, consumer_free_stream);
 }
 
 /*
This page took 0.025369 seconds and 4 git commands to generate.