]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
finisher: wait_for_empty
authorSage Weil <sage@newdream.net>
Tue, 26 Jan 2010 00:24:25 +0000 (16:24 -0800)
committerSage Weil <sage@newdream.net>
Tue, 26 Jan 2010 00:24:25 +0000 (16:24 -0800)
src/common/Finisher.cc
src/common/Finisher.h

index 3dbe2ceee8f6d2497086e50c13bf51581ec41c0d..fb0f8e0fa1273f954f683e8d44df28b8482ab1e0 100644 (file)
@@ -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;
     
index 0cd95cb5625d6f8fd7f6f9cc630dc63d750be52e..94291b494dd9aaa0875a2dfb29ef7c7a42e3d45b 100644 (file)
@@ -21,7 +21,7 @@
 
 class Finisher {
   Mutex          finisher_lock;
-  Cond           finisher_cond;
+  Cond           finisher_cond, finisher_empty_cond;
   bool           finisher_stop;
   vector<Context*> finisher_queue;
   list<pair<Context*,int> > 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) {}
 };