diff --git a/thread/prioritizedworkqueue.cpp b/thread/prioritizedworkqueue.cpp index 7f193fc407..ea54d35dac 100644 --- a/thread/prioritizedworkqueue.cpp +++ b/thread/prioritizedworkqueue.cpp @@ -1,5 +1,6 @@ #include "base/functional.h" #include "base/logging.h" +#include "base/timeutil.h" #include "thread/thread.h" #include "thread/prioritizedworkqueue.h" @@ -66,6 +67,20 @@ PrioritizedWorkQueueItem *PrioritizedWorkQueue::Pop() { } } +void PrioritizedWorkQueue::Wait(PrioritizedWorkQueueItem *item) { + while (true) { + bool stillThere = false; + lock_guard guard(mutex_); + for (int i = 0; i < queue_.empty(); i++) { + if (queue_[i] == item) + stillThere = true; + } + if (!stillThere) + break; + sleep_ms(100); + } +} + // TODO: This feels ugly. Revisit later. static std::thread *workThread; diff --git a/thread/prioritizedworkqueue.h b/thread/prioritizedworkqueue.h index c2198a3d5b..506e3146b0 100644 --- a/thread/prioritizedworkqueue.h +++ b/thread/prioritizedworkqueue.h @@ -35,6 +35,9 @@ public: bool Done() { return done_; } void Stop(); + // Try not to use this. It's a hack. + void Wait(PrioritizedWorkQueueItem *item); + private: bool done_; recursive_mutex mutex_; @@ -49,4 +52,4 @@ private: // Starts up a thread that keeps trying to run this workqueue. // TODO: This feels ugly. Revisit later. void ProcessWorkQueueOnThreadWhile(PrioritizedWorkQueue *wq); -void StopProcessingWorkQueue(PrioritizedWorkQueue *wq); \ No newline at end of file +void StopProcessingWorkQueue(PrioritizedWorkQueue *wq);