Commit 28623f8e authored by Sergey Abbakumov's avatar Sergey Abbakumov Committed by Commit Bot

Notify the thread when the lock is held

In Watchdog implementation we notify another thread not holding the
lock. Here
https://www.chromium.org/developers/lock-and-condition-variable it's
stated we need to put Signal() inside the critical section to avoid hard
to find bugs.


Change-Id: I60725d2a33a87ff9067b779f11b372a22e006e10
Reviewed-on: https://chromium-review.googlesource.com/1018462Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561375}
parent 74fca1c3
......@@ -6,6 +6,7 @@
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "base/threading/platform_thread.h"
namespace base {
......@@ -31,8 +32,8 @@ struct StaticData {
};
StaticData* GetStaticData() {
static auto* static_data = new StaticData();
return static_data;
static base::NoDestructor<StaticData> static_data;
return static_data.get();
}
} // namespace
......@@ -62,17 +63,14 @@ Watchdog::~Watchdog() {
return;
if (!IsJoinable())
Cleanup();
condition_variable_.Signal();
PlatformThread::Join(handle_);
}
void Watchdog::Cleanup() {
if (!enabled_)
return;
{
AutoLock lock(lock_);
state_ = SHUTDOWN;
}
condition_variable_.Signal();
}
......@@ -93,11 +91,9 @@ void Watchdog::ArmSomeTimeDeltaAgo(const TimeDelta& time_delta) {
// Start clock for watchdog.
void Watchdog::ArmAtStartTime(const TimeTicks start_time) {
{
AutoLock lock(lock_);
start_time_ = start_time;
state_ = ARMED;
}
// Force watchdog to wake up, and go to sleep with the timer ticking with the
// proper duration.
condition_variable_.Signal();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment