X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcommon%2Fconsumer-metadata-cache.c;h=4c8a665af0db7aa1d5d8224edcfac96c5fc2fbb2;hb=7f725ec5735e080b377f9c3459664fac0ec2baff;hp=888d82f3accae8e5644c7bb42c4b39747d597e2e;hpb=331744e34f56a5aec69b05d356d6901e67926acc;p=lttng-tools.git diff --git a/src/common/consumer-metadata-cache.c b/src/common/consumer-metadata-cache.c index 888d82f3a..4c8a665af 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,35 @@ int consumer_metadata_cache_flushed(struct lttng_consumer_channel *channel, 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. + */ + pthread_mutex_lock(&consumer_data.lock); + pthread_mutex_lock(&channel->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(&channel->lock); + pthread_mutex_unlock(&consumer_data.lock); return ret; }