Fix: remove bad check after epoll wait in consumer
[lttng-tools.git] / src / common / consumer-metadata-cache.c
index c6e6c6b164a423b81dace0312ee3c71c9cb3626e..473ab231a9100a278afec61c1844738e1f027df2 100644 (file)
@@ -193,7 +193,7 @@ 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;
@@ -203,8 +203,17 @@ int consumer_metadata_cache_flushed(struct lttng_consumer_channel *channel,
 
        cache = channel->metadata_cache;
 
-       pthread_mutex_lock(&consumer_data.lock);
-       pthread_mutex_lock(&channel->lock);
+       /*
+        * 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).
+        */
+       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) {
@@ -225,8 +234,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.024175 seconds and 4 git commands to generate.