[android] change lock scope in run_loop to avoid deadlocks. simplify as

well
This commit is contained in:
Ivo van Dongen
2019-02-12 11:43:18 +02:00
committed by Ivo van Dongen
parent ca7d9422b6
commit 1fadf56368
4 changed files with 31 additions and 46 deletions

View File

@@ -10,21 +10,20 @@ namespace util {
class Timer::Impl : public RunLoop::Impl::Runnable {
public:
Impl() {
loop->initRunnable(this);
}
Impl() = default;
~Impl() {
stop();
}
void start(Duration timeout, Duration repeat_, std::function<void ()>&& task_) {
void start(Duration timeout, Duration repeat_, std::function<void()>&& task_) {
stop();
repeat = repeat_;
task = std::move(task_);
// Prevent overflows when timeout is set to Duration::max()
due = (timeout == Duration::max()) ? std::chrono::time_point<Clock>::max() : Clock::now() + timeout;
due = (timeout == Duration::max()) ? std::chrono::time_point<Clock>::max() : Clock::now() +
timeout;
loop->addRunnable(this);
}
@@ -59,8 +58,7 @@ private:
std::function<void()> task;
};
Timer::Timer()
: impl(std::make_unique<Impl>()) {
Timer::Timer() : impl(std::make_unique<Impl>()) {
}
Timer::~Timer() = default;