From: David Goulet Date: Mon, 3 Jun 2013 17:24:10 +0000 (-0400) Subject: Fix: add more conditions and a lock to metadata cache flushed X-Git-Tag: v2.2.0-rc3~35 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=fe81e5c901c1dd23495620c8efd9e1ed6df86c8b;p=lttng-tools.git Fix: add more conditions and a lock to metadata cache flushed Some more conditions applies to return if the metadata cache is indeed flushed. If no metadata stream is found or the endpoint status is set to something other than ACTIVE, this means the channel is being (or will be) destroyed thus the metadata cache can't be updated so is indeed "flushed". Acked-by: Mathieu Desnoyers Acked-by: Julien Desfossez Signed-off-by: David Goulet --- diff --git a/src/common/consumer-metadata-cache.c b/src/common/consumer-metadata-cache.c index 888d82f3a..0c20e7fc7 100644 --- a/src/common/consumer-metadata-cache.c +++ b/src/common/consumer-metadata-cache.c @@ -33,6 +33,8 @@ #include "consumer-metadata-cache.h" +extern struct lttng_consumer_global_data consumer_data; + /* * Extend the allocated size of the metadata cache. Called only from * lttng_ustconsumer_write_metadata_cache. @@ -201,13 +203,28 @@ int consumer_metadata_cache_flushed(struct lttng_consumer_channel *channel, cache = channel->metadata_cache; + pthread_mutex_lock(&consumer_data.lock); pthread_mutex_lock(&channel->metadata_cache->lock); + if (cache->rb_pushed >= offset) { ret = 0; + } else if (!channel->metadata_stream) { + /* + * Having no metadata stream means the channel is being destroyed so there + * is no cache to flush anymore. + */ + ret = 0; + } else if (channel->metadata_stream->endpoint_status != + CONSUMER_ENDPOINT_ACTIVE) { + /* An inactive endpoint means we don't have to flush anymore. */ + ret = 0; } else { + /* Still not completely flushed. */ ret = 1; } + pthread_mutex_unlock(&channel->metadata_cache->lock); + pthread_mutex_unlock(&consumer_data.lock); return ret; }