+ return done_flushing;
+}
+} /* namespace */
+
+/*
+ * Wait until the cache is flushed up to the offset passed in parameter or the
+ * metadata stream has been destroyed.
+ */
+void consumer_wait_metadata_cache_flushed(struct lttng_consumer_channel *channel,
+ uint64_t offset,
+ bool invoked_by_timer)
+{
+ assert(channel);
+ assert(channel->metadata_cache);
+
+ if (consumer_metadata_cache_is_flushed(channel, offset, invoked_by_timer)) {
+ return;
+ }
+
+ /* Metadata cache is not currently flushed, wait on wait queue. */
+ for (;;) {
+ struct lttng_waiter waiter;
+
+ lttng_waiter_init(&waiter);
+ lttng_wait_queue_add(&channel->metadata_pushed_wait_queue, &waiter);
+ if (consumer_metadata_cache_is_flushed(channel, offset, invoked_by_timer)) {
+ /* Wake up all waiters, ourself included. */
+ lttng_wait_queue_wake_all(&channel->metadata_pushed_wait_queue);
+ /* Ensure proper teardown of waiter. */
+ lttng_waiter_wait(&waiter);
+ break;
+ }
+
+ lttng_waiter_wait(&waiter);
+ }