From c38d320689f2a81f663f5446a09d16e84a422dee Mon Sep 17 00:00:00 2001 From: Chris Dziemborowicz Date: Wed, 31 Jan 2018 12:52:24 -0800 Subject: [PATCH] Add AsyncInvoker::Clear method to allow canceling pending invocations Change-Id: I85707c0980cdfb64acbb61ff8b6245e8da509db8 Bug: webrtc:8823 Reviewed-on: https://webrtc-review.googlesource.com/46801 Commit-Queue: Chris Dziemborowicz Reviewed-by: Taylor Brandstetter Cr-Commit-Position: refs/heads/master@{#21835} --- rtc_base/asyncinvoker.cc | 4 ++++ rtc_base/asyncinvoker.h | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/rtc_base/asyncinvoker.cc b/rtc_base/asyncinvoker.cc index 7f65dfc35f..7033c1a834 100644 --- a/rtc_base/asyncinvoker.cc +++ b/rtc_base/asyncinvoker.cc @@ -67,6 +67,10 @@ void AsyncInvoker::Flush(Thread* thread, uint32_t id /*= MQID_ANY*/) { } } +void AsyncInvoker::Clear() { + MessageQueueManager::Clear(this); +} + void AsyncInvoker::DoInvoke(const Location& posted_from, Thread* thread, std::unique_ptr closure, diff --git a/rtc_base/asyncinvoker.h b/rtc_base/asyncinvoker.h index 3f0c4f1eb5..523e9a95d1 100644 --- a/rtc_base/asyncinvoker.h +++ b/rtc_base/asyncinvoker.h @@ -124,6 +124,11 @@ class AsyncInvoker : public MessageHandler { // behavior is desired, call Flush() before destroying this object. void Flush(Thread* thread, uint32_t id = MQID_ANY); + // Cancels any outstanding calls we own that are pending on any thread, and + // which have not yet started to execute. This does not wait for any calls + // that have already started executing to complete. + void Clear(); + private: void OnMessage(Message* msg) override; void DoInvoke(const Location& posted_from,