Cleanup: document RCU read-side lock better
[lttng-tools.git] / src / common / ust-consumer / ust-consumer.c
index 44a8240b055e55dd798e98874f642f1efc72c414..8c15c7e135016098f3cb90a94923ec9eb3fc9d93 100644 (file)
@@ -581,6 +581,7 @@ static int flush_channel(uint64_t chan_key)
 
        DBG("UST consumer flush channel key %" PRIu64, chan_key);
 
+       rcu_read_lock();
        channel = consumer_find_channel(chan_key);
        if (!channel) {
                ERR("UST consumer flush channel %" PRIu64 " not found", chan_key);
@@ -591,20 +592,19 @@ static int flush_channel(uint64_t chan_key)
        ht = consumer_data.stream_per_chan_id_ht;
 
        /* For each stream of the channel id, flush it. */
-       rcu_read_lock();
        cds_lfht_for_each_entry_duplicate(ht->ht,
                        ht->hash_fct(&channel->key, lttng_ht_seed), ht->match_fct,
                        &channel->key, &iter.iter, stream, node_channel_id.node) {
                        ustctl_flush_buffer(stream->ustream, 1);
        }
-       rcu_read_unlock();
-
 error:
+       rcu_read_unlock();
        return ret;
 }
 
 /*
  * Close metadata stream wakeup_fd using the given key to retrieve the channel.
+ * RCU read side lock MUST be acquired before calling this function.
  *
  * Return 0 on success else an LTTng error code.
  */
@@ -859,13 +859,6 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
                        goto end_channel_error;
                }
 
-               /*
-                * Set refcount to 1 for owner. Below, we will pass
-                * ownership to the consumer_thread_channel_poll()
-                * thread.
-                */
-               channel->refcount = 1;
-
                /* Build channel attributes from received message. */
                attr.subbuf_size = msg.u.ask_channel.subbuf_size;
                attr.num_subbuf = msg.u.ask_channel.num_subbuf;
@@ -890,6 +883,12 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
                case LTTNG_UST_CHAN_PER_CPU:
                        channel->type = CONSUMER_CHANNEL_TYPE_DATA;
                        attr.type = LTTNG_UST_CHAN_PER_CPU;
+                       /*
+                        * Set refcount to 1 for owner. Below, we will
+                        * pass ownership to the
+                        * consumer_thread_channel_poll() thread.
+                        */
+                       channel->refcount = 1;
                        break;
                case LTTNG_UST_CHAN_METADATA:
                        channel->type = CONSUMER_CHANNEL_TYPE_METADATA;
This page took 0.023913 seconds and 4 git commands to generate.