diff options
Diffstat (limited to 'base/synchronization/waitable_event_watcher_posix.cc')
-rw-r--r-- | base/synchronization/waitable_event_watcher_posix.cc | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/base/synchronization/waitable_event_watcher_posix.cc b/base/synchronization/waitable_event_watcher_posix.cc index 3adbc5f977..2b296dafd7 100644 --- a/base/synchronization/waitable_event_watcher_posix.cc +++ b/base/synchronization/waitable_event_watcher_posix.cc @@ -46,7 +46,7 @@ class Flag : public RefCountedThreadSafe<Flag> { private: friend class RefCountedThreadSafe<Flag>; - ~Flag() {} + ~Flag() = default; mutable Lock lock_; bool flag_; @@ -61,16 +61,16 @@ class Flag : public RefCountedThreadSafe<Flag> { class AsyncWaiter : public WaitableEvent::Waiter { public: AsyncWaiter(scoped_refptr<SequencedTaskRunner> task_runner, - const base::Closure& callback, + base::OnceClosure callback, Flag* flag) : task_runner_(std::move(task_runner)), - callback_(callback), + callback_(std::move(callback)), flag_(flag) {} bool Fire(WaitableEvent* event) override { // Post the callback if we haven't been cancelled. if (!flag_->value()) - task_runner_->PostTask(FROM_HERE, callback_); + task_runner_->PostTask(FROM_HERE, std::move(callback_)); // We are removed from the wait-list by the WaitableEvent itself. It only // remains to delete ourselves. @@ -86,7 +86,7 @@ class AsyncWaiter : public WaitableEvent::Waiter { private: const scoped_refptr<SequencedTaskRunner> task_runner_; - const base::Closure callback_; + base::OnceClosure callback_; const scoped_refptr<Flag> flag_; }; @@ -96,13 +96,13 @@ class AsyncWaiter : public WaitableEvent::Waiter { // of when the event is canceled. // ----------------------------------------------------------------------------- void AsyncCallbackHelper(Flag* flag, - const WaitableEventWatcher::EventCallback& callback, + WaitableEventWatcher::EventCallback callback, WaitableEvent* event) { // Runs on the sequence that called StartWatching(). if (!flag->value()) { // This is to let the WaitableEventWatcher know that the event has occured. flag->Set(); - callback.Run(event); + std::move(callback).Run(event); } } @@ -124,9 +124,9 @@ WaitableEventWatcher::~WaitableEventWatcher() { // ----------------------------------------------------------------------------- bool WaitableEventWatcher::StartWatching( WaitableEvent* event, - const EventCallback& callback) { + EventCallback callback, + scoped_refptr<SequencedTaskRunner> task_runner) { DCHECK(sequence_checker_.CalledOnValidSequence()); - DCHECK(SequencedTaskRunnerHandle::Get()); // A user may call StartWatching from within the callback function. In this // case, we won't know that we have finished watching, expect that the Flag @@ -137,8 +137,9 @@ bool WaitableEventWatcher::StartWatching( DCHECK(!cancel_flag_) << "StartWatching called while still watching"; cancel_flag_ = new Flag; - const Closure internal_callback = base::Bind( - &AsyncCallbackHelper, base::RetainedRef(cancel_flag_), callback, event); + OnceClosure internal_callback = + base::BindOnce(&AsyncCallbackHelper, base::RetainedRef(cancel_flag_), + std::move(callback), event); WaitableEvent::WaitableEventKernel* kernel = event->kernel_.get(); AutoLock locked(kernel->lock_); @@ -148,14 +149,14 @@ bool WaitableEventWatcher::StartWatching( kernel->signaled_ = false; // No hairpinning - we can't call the delegate directly here. We have to - // post a task to the SequencedTaskRunnerHandle as usual. - SequencedTaskRunnerHandle::Get()->PostTask(FROM_HERE, internal_callback); + // post a task to |task_runner| as usual. + task_runner->PostTask(FROM_HERE, std::move(internal_callback)); return true; } kernel_ = kernel; - waiter_ = new AsyncWaiter(SequencedTaskRunnerHandle::Get(), internal_callback, - cancel_flag_.get()); + waiter_ = new AsyncWaiter(std::move(task_runner), + std::move(internal_callback), cancel_flag_.get()); event->Enqueue(waiter_); return true; @@ -170,7 +171,7 @@ void WaitableEventWatcher::StopWatching() { if (cancel_flag_->value()) { // In this case, the event has fired, but we haven't figured that out yet. // The WaitableEvent may have been deleted too. - cancel_flag_ = NULL; + cancel_flag_ = nullptr; return; } @@ -184,7 +185,7 @@ void WaitableEventWatcher::StopWatching() { // delegate getting called. If the task has run then we have the last // reference to the flag and it will be deleted immedately after. cancel_flag_->Set(); - cancel_flag_ = NULL; + cancel_flag_ = nullptr; return; } @@ -210,7 +211,7 @@ void WaitableEventWatcher::StopWatching() { // have been enqueued with the MessageLoop because the waiter was never // signaled) delete waiter_; - cancel_flag_ = NULL; + cancel_flag_ = nullptr; return; } @@ -219,7 +220,7 @@ void WaitableEventWatcher::StopWatching() { // task on the SequencedTaskRunner, but to delete it instead. The Waiter // deletes itself once run. cancel_flag_->Set(); - cancel_flag_ = NULL; + cancel_flag_ = nullptr; // If the waiter has already run then the task has been enqueued. If the Task // hasn't yet run, the flag will stop the delegate from getting called. (This |