Index: webrtc/base/messagequeue.h |
diff --git a/webrtc/base/messagequeue.h b/webrtc/base/messagequeue.h |
index e39c9f9869a4b19ee16c225cdd20bfee7121c412..2a5176ff60314da3a14dc62f2d93bf2fcac3c8bc 100644 |
--- a/webrtc/base/messagequeue.h |
+++ b/webrtc/base/messagequeue.h |
@@ -147,6 +147,22 @@ class DisposeData : public MessageData { |
T* data_; |
}; |
+class CallableData : public MessageData { |
+ public: |
+ virtual void call(void) = 0; |
kwiberg-webrtc
2017/06/26 13:07:48
"Call"
nisse-webrtc
2017/06/27 08:27:17
Done.
|
+}; |
+ |
+template <class FunctorT> |
+class FunctorData : public CallableData { |
+ public: |
+ explicit FunctorData(FunctorT functor) |
+ : functor_(std::move(functor)) {} |
+ void call(void) override { functor_(); } |
+ |
+ private: |
+ FunctorT functor_; |
+}; |
+ |
const uint32_t MQID_ANY = static_cast<uint32_t>(-1); |
const uint32_t MQID_DISPOSE = static_cast<uint32_t>(-2); |
@@ -236,6 +252,15 @@ class MessageQueue { |
uint32_t id = 0, |
MessageData* pdata = nullptr, |
bool time_sensitive = false); |
+ // TODO(nisse): Can this be renamed to just Post? Needs some |
+ // additional type check, or else it collides with calls to the |
+ // above Post method with optional arguments omitted. |
kwiberg-webrtc
2017/06/26 13:07:48
Should be simple to do by e.g. using enable_if to
nisse-webrtc
2017/06/27 08:27:17
Done.
|
+ template <class FunctorT> |
+ void PostFunctor(const Location& posted_from, FunctorT functor) { |
+ PostFunctorInternal(posted_from, |
+ new FunctorData<FunctorT>(std::move(functor))); |
+ } |
+ |
virtual void PostDelayed(const Location& posted_from, |
int cmsDelay, |
MessageHandler* phandler, |
@@ -312,6 +337,9 @@ class MessageQueue { |
bool fDestroyed_; |
private: |
+ void PostFunctorInternal(const Location& posted_from, |
+ CallableData* message_data); |
+ |
volatile int stop_; |
// The SocketServer might not be owned by MessageQueue. |