Index: webrtc/base/messagequeue.h |
diff --git a/webrtc/base/messagequeue.h b/webrtc/base/messagequeue.h |
index e39c9f9869a4b19ee16c225cdd20bfee7121c412..8981d799783aaf166174845a5657110b6774a540 100644 |
--- a/webrtc/base/messagequeue.h |
+++ b/webrtc/base/messagequeue.h |
@@ -147,6 +147,21 @@ class DisposeData : public MessageData { |
T* data_; |
}; |
+class CallableData : public MessageData { |
+ public: |
+ virtual void Call(void) = 0; |
tommi
2017/06/27 12:01:14
virtual void Call() = 0;
Btw, this seems to now b
kwiberg-webrtc
2017/06/27 13:14:56
sgtm---the new Post() call could take a unique_ptr
nisse-webrtc
2017/06/28 11:47:54
Done.
tommi
2017/06/28 13:17:33
yes, I think so
nisse-webrtc
2017/06/29 10:40:31
I've renamed Call to Run, and Callable to Runnable
nisse-webrtc
2017/06/29 10:40:32
Sounds like it could work, I'll give it a try, but
|
+}; |
+ |
+template <class FunctorT> |
+class FunctorData : public CallableData { |
+ public: |
+ explicit FunctorData(FunctorT functor) : functor_(std::move(functor)) {} |
+ void Call(void) override { functor_(); } |
tommi
2017/06/27 12:01:14
same here (no 'void' when there aren't any argumen
|
+ |
+ 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 +251,17 @@ class MessageQueue { |
uint32_t id = 0, |
MessageData* pdata = nullptr, |
bool time_sensitive = false); |
+ |
+ // Additional type check, or else it collides with calls to the |
+ // above Post method with the optional arguments omitted. |
+ template <class FunctorT, |
+ typename std::enable_if<!std::is_pointer<FunctorT>::value>::type* = |
+ nullptr> |
+ void Post(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 +338,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. |