From f2b5b52f6abd64b14b8a935c397323bf08ae61a8 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 25 Jan 2010 16:24:25 -0800 Subject: [PATCH] finisher: wait_for_empty --- src/common/Finisher.cc | 9 +++++++++ src/common/Finisher.h | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/common/Finisher.cc b/src/common/Finisher.cc index 3dbe2ceee8f6d..fb0f8e0fa1273 100644 --- a/src/common/Finisher.cc +++ b/src/common/Finisher.cc @@ -16,6 +16,14 @@ void Finisher::stop() finisher_thread.join(); } +void Finisher::wait_for_empty() +{ + finisher_lock.Lock(); + while (!finisher_queue.empty()) + finisher_cond.Wait(finisher_lock); + finisher_lock.Unlock(); +} + void *Finisher::finisher_thread_entry() { finisher_lock.Lock(); @@ -46,6 +54,7 @@ void *Finisher::finisher_thread_entry() ls.clear(); finisher_lock.Lock(); + finisher_empty_cond.Signal(); } if (finisher_stop) break; diff --git a/src/common/Finisher.h b/src/common/Finisher.h index 0cd95cb5625d6..94291b494dd9a 100644 --- a/src/common/Finisher.h +++ b/src/common/Finisher.h @@ -21,7 +21,7 @@ class Finisher { Mutex finisher_lock; - Cond finisher_cond; + Cond finisher_cond, finisher_empty_cond; bool finisher_stop; vector finisher_queue; list > finisher_queue_rval; @@ -63,6 +63,8 @@ class Finisher { void start(); void stop(); + void wait_for_empty(); + Finisher() : finisher_lock("Finisher::finisher_lock"), finisher_stop(false), finisher_thread(this) {} }; -- 2.39.5