aboutsummaryrefslogtreecommitdiff
path: root/src/scheduler.cpp
diff options
context:
space:
mode:
authorCasey Rodarmor <casey@rodarmor.com>2015-08-17 17:30:46 -0400
committerCasey Rodarmor <casey@rodarmor.com>2015-08-18 10:40:13 -0400
commitfb08d92312312c6c896327d264a8e9915fdafae7 (patch)
tree3bf610d11f4966df598f0685aa2e9f04ff378fb0 /src/scheduler.cpp
parent1e92b275406e3fbc7ab59d2ada1c882ca15fb36f (diff)
Make sure we re-acquire lock if a task throws
Diffstat (limited to 'src/scheduler.cpp')
-rw-r--r--src/scheduler.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/scheduler.cpp b/src/scheduler.cpp
index d5bb588b71..06115f5619 100644
--- a/src/scheduler.cpp
+++ b/src/scheduler.cpp
@@ -6,6 +6,7 @@
#include <assert.h>
#include <boost/bind.hpp>
+#include <boost/thread/reverse_lock.hpp>
#include <utility>
CScheduler::CScheduler() : nThreadsServicingQueue(0), stopRequested(false), stopWhenEmpty(false)
@@ -65,11 +66,12 @@ void CScheduler::serviceQueue()
Function f = taskQueue.begin()->second;
taskQueue.erase(taskQueue.begin());
- // Unlock before calling f, so it can reschedule itself or another task
- // without deadlocking:
- lock.unlock();
- f();
- lock.lock();
+ {
+ // Unlock before calling f, so it can reschedule itself or another task
+ // without deadlocking:
+ boost::reverse_lock<boost::unique_lock<boost::mutex> > rlock(lock);
+ f();
+ }
} catch (...) {
--nThreadsServicingQueue;
throw;