Make rtc::Thread a TaskQueue
in support of converging on single way to run asynchronous tasks in webrtc Bug: b/144982320 Change-Id: I200ad298136d11764a3f5c0547ebcba51aceafa0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/158782 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29896}
This commit is contained in:
committed by
Commit Bot
parent
2aaf4afb09
commit
912b3b83b3
@ -21,6 +21,8 @@
|
||||
#if defined(WEBRTC_POSIX)
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
#include "api/task_queue/queued_task.h"
|
||||
#include "api/task_queue/task_queue_base.h"
|
||||
#include "rtc_base/constructor_magic.h"
|
||||
#include "rtc_base/location.h"
|
||||
#include "rtc_base/message_handler.h"
|
||||
@ -133,7 +135,8 @@ struct _SendMessage {
|
||||
|
||||
// WARNING! SUBCLASSES MUST CALL Stop() IN THEIR DESTRUCTORS! See ~Thread().
|
||||
|
||||
class RTC_LOCKABLE RTC_EXPORT Thread : public MessageQueue {
|
||||
class RTC_LOCKABLE RTC_EXPORT Thread : public MessageQueue,
|
||||
public webrtc::TaskQueueBase {
|
||||
public:
|
||||
explicit Thread(SocketServer* ss);
|
||||
explicit Thread(std::unique_ptr<SocketServer> ss);
|
||||
@ -263,6 +266,12 @@ class RTC_LOCKABLE RTC_EXPORT Thread : public MessageQueue {
|
||||
std::forward<FunctorT>(functor)));
|
||||
}
|
||||
|
||||
// From TaskQueueBase
|
||||
void PostTask(std::unique_ptr<webrtc::QueuedTask> task) override;
|
||||
void PostDelayedTask(std::unique_ptr<webrtc::QueuedTask> task,
|
||||
uint32_t milliseconds) override;
|
||||
void Delete() override;
|
||||
|
||||
// From MessageQueue
|
||||
bool IsProcessingMessagesForTesting() override;
|
||||
void Clear(MessageHandler* phandler,
|
||||
@ -325,6 +334,10 @@ class RTC_LOCKABLE RTC_EXPORT Thread : public MessageQueue {
|
||||
friend class ScopedDisallowBlockingCalls;
|
||||
|
||||
private:
|
||||
class QueuedTaskHandler final : public MessageHandler {
|
||||
public:
|
||||
void OnMessage(Message* msg) override;
|
||||
};
|
||||
// Sets the per-thread allow-blocking-calls flag and returns the previous
|
||||
// value. Must be called on this thread.
|
||||
bool SetAllowBlockingCalls(bool allow);
|
||||
@ -381,6 +394,9 @@ class RTC_LOCKABLE RTC_EXPORT Thread : public MessageQueue {
|
||||
// Only touched from the worker thread itself.
|
||||
bool blocking_calls_allowed_ = true;
|
||||
|
||||
// Runs webrtc::QueuedTask posted to the Thread.
|
||||
QueuedTaskHandler queued_task_handler_;
|
||||
|
||||
friend class ThreadManager;
|
||||
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(Thread);
|
||||
|
||||
Reference in New Issue
Block a user