+ 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 (;;) {
+ lttng::synchro::waiter waiter;
+
+ channel->metadata_pushed_wait_queue.add(waiter);
+ if (consumer_metadata_cache_is_flushed(channel, offset, invoked_by_timer)) {
+ /* Wake up all waiters, ourself included. */
+ channel->metadata_pushed_wait_queue.wake_all();
+ /* Ensure proper teardown of waiter. */
+ waiter.wait();
+ break;
+ }
+
+ waiter.wait();
+ }