diff options
author | Casey Rodarmor <casey@rodarmor.com> | 2015-08-17 17:30:46 -0400 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2015-09-22 00:43:13 +0000 |
commit | 626c5e69360aabb766e139c7ea19963fb8edf226 (patch) | |
tree | 72008d8a92461110e5b6b8e16712e897aa5b9e8e | |
parent | 48770534a6826ad3426ec83ce3de8868b22db8a6 (diff) |
Make sure we re-acquire lock if a task throws
-rw-r--r-- | src/scheduler.cpp | 12 |
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; |