Documentation of live usage and protocol
[lttng-tools.git] / src / common / consumer-metadata-cache.c
index 4c8a665af0db7aa1d5d8224edcfac96c5fc2fbb2..d597e64e37883c91182bcaf9c54327cd9cc0d54f 100644 (file)
@@ -105,15 +105,17 @@ int consumer_metadata_cache_write(struct lttng_consumer_channel *channel,
        }
 
        if (cache->max_offset == cache->total_bytes_written) {
-               offset = cache->rb_pushed;
-               len = cache->total_bytes_written - cache->rb_pushed;
-               ret = lttng_ustconsumer_push_metadata(channel, cache->data, offset,
-                               len);
-               if (ret < 0) {
-                       ERR("Pushing metadata");
-                       goto end;
+               char dummy = 'c';
+
+               cache->contiguous = cache->max_offset;
+               if (channel->monitor) {
+                       ret = write(channel->metadata_stream->ust_metadata_poll_pipe[1],
+                                       &dummy, 1);
+                       if (ret < 1) {
+                               ERR("Wakeup UST metadata pipe");
+                               goto end;
+                       }
                }
-               cache->rb_pushed += len;
        }
 
 end:
@@ -177,11 +179,6 @@ void consumer_metadata_cache_destroy(struct lttng_consumer_channel *channel)
 
        DBG("Destroying metadata cache");
 
-       if (channel->metadata_cache->max_offset >
-                       channel->metadata_cache->rb_pushed) {
-               ERR("Destroying a cache not entirely commited");
-       }
-
        pthread_mutex_destroy(&channel->metadata_cache->lock);
        free(channel->metadata_cache->data);
        free(channel->metadata_cache);
@@ -193,33 +190,37 @@ void consumer_metadata_cache_destroy(struct lttng_consumer_channel *channel)
  * Return 0 if everything has been flushed, 1 if there is data not flushed.
  */
 int consumer_metadata_cache_flushed(struct lttng_consumer_channel *channel,
-               uint64_t offset)
+               uint64_t offset, int timer)
 {
-       int ret;
-       struct consumer_metadata_cache *cache;
+       int ret = 0;
+       struct lttng_consumer_stream *metadata_stream;
 
        assert(channel);
        assert(channel->metadata_cache);
 
-       cache = channel->metadata_cache;
-
        /*
-        * XXX This consumer_data.lock should eventually be replaced by
-        * a channel lock. It protects metadata_stream read and endpoint
-        * status check.
+        * If not called from a timer handler, we have to take the
+        * channel lock to be mutually exclusive with channel teardown.
+        * Timer handler does not need to take this lock because it is
+        * already synchronized by timer stop (and, more importantly,
+        * taking this lock in a timer handler would cause a deadlock).
         */
-       pthread_mutex_lock(&consumer_data.lock);
-       pthread_mutex_lock(&channel->lock);
+       if (!timer) {
+               pthread_mutex_lock(&channel->lock);
+       }
+       pthread_mutex_lock(&channel->timer_lock);
        pthread_mutex_lock(&channel->metadata_cache->lock);
 
-       if (cache->rb_pushed >= offset) {
-               ret = 0;
-       } else if (!channel->metadata_stream) {
+       metadata_stream = channel->metadata_stream;
+
+       if (!metadata_stream) {
                /*
                 * Having no metadata stream means the channel is being destroyed so there
                 * is no cache to flush anymore.
                 */
                ret = 0;
+       } else if (metadata_stream->ust_metadata_pushed >= offset) {
+               ret = 0;
        } else if (channel->metadata_stream->endpoint_status !=
                        CONSUMER_ENDPOINT_ACTIVE) {
                /* An inactive endpoint means we don't have to flush anymore. */
@@ -230,8 +231,10 @@ int consumer_metadata_cache_flushed(struct lttng_consumer_channel *channel,
        }
 
        pthread_mutex_unlock(&channel->metadata_cache->lock);
-       pthread_mutex_unlock(&channel->lock);
-       pthread_mutex_unlock(&consumer_data.lock);
+       pthread_mutex_unlock(&channel->timer_lock);
+       if (!timer) {
+               pthread_mutex_unlock(&channel->lock);
+       }
 
        return ret;
 }
This page took 0.024223 seconds and 4 git commands to generate.