Skip to content

Commit

Permalink
Use lock_guard instead of lock.lock()/unlock() in Watchdog in order t…
Browse files Browse the repository at this point in the history
…o avoid relocking when an unlock exception is thrown.
  • Loading branch information
FooBarWidget committed Oct 19, 2011
1 parent c955c2c commit 476c7d1
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ext/common/Watchdog.cpp
Expand Up @@ -107,9 +107,10 @@ class AgentWatcher {
int status, e;

while (!this_thread::interruption_requested()) {
lock.lock();
pid = this->pid;
lock.unlock();
{
lock_guard<boost::mutex> l(lock);
pid = this->pid;
}

// Process can be started before the watcher thread is launched.
if (pid == 0) {
Expand All @@ -132,9 +133,10 @@ class AgentWatcher {
e = errno;
}

lock.lock();
this->pid = 0;
lock.unlock();
{
lock_guard<boost::mutex> l(lock);
this->pid = 0;
}

this_thread::disable_interruption di;
this_thread::disable_syscall_interruption dsi;
Expand Down

0 comments on commit 476c7d1

Please sign in to comment.