Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Unified Diff: webrtc/base/messagequeue.h

Issue 2915253002: Delete SignalThread class. (Closed)
Patch Set: Fix template magic. Naming and formatting fixes. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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.
« no previous file with comments | « webrtc/base/BUILD.gn ('k') | webrtc/base/messagequeue.cc » ('j') | webrtc/base/messagequeue.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698