Chromium Code Reviews| Index: webrtc/api/proxy.h |
| diff --git a/webrtc/api/proxy.h b/webrtc/api/proxy.h |
| index 746a758ba4315181cfb04688487fa1d70179eb0c..896e6ddba37027951f7873d556fbbf907893bc85 100644 |
| --- a/webrtc/api/proxy.h |
| +++ b/webrtc/api/proxy.h |
| @@ -318,7 +318,7 @@ class MethodCall5 : public rtc::Message, |
| : signaling_thread_(signaling_thread), c_(c) {} \ |
| ~c##ProxyWithInternal() { \ |
| MethodCall0<c##ProxyWithInternal, void> call( \ |
| - this, &c##ProxyWithInternal::Release_s); \ |
| + this, &c##ProxyWithInternal::ReleaseOnCorrectThread); \ |
| call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
| } \ |
| \ |
| @@ -348,7 +348,7 @@ class MethodCall5 : public rtc::Message, |
| c_(c) {} \ |
| ~c##ProxyWithInternal() { \ |
| MethodCall0<c##ProxyWithInternal, void> call( \ |
| - this, &c##ProxyWithInternal::Release_s); \ |
| + this, &c##ProxyWithInternal::ReleaseOnCorrectThread); \ |
| call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
| } \ |
| \ |
| @@ -363,6 +363,71 @@ class MethodCall5 : public rtc::Message, |
| const INTERNAL_CLASS* internal() const { return c_.get(); } \ |
| INTERNAL_CLASS* internal() { return c_.get(); } |
| +#define BEGIN_NON_REFCOUNTED_PROXY_MAP(c) \ |
|
Taylor Brandstetter
2017/01/13 07:52:29
Before you say "wow these macros are getting out o
|
| + template <class INTERNAL_CLASS> \ |
| + class c##ProxyWithInternal; \ |
| + typedef c##ProxyWithInternal<c##Interface> c##Proxy; \ |
| + template <class INTERNAL_CLASS> \ |
| + class c##ProxyWithInternal : public c##Interface { \ |
| + protected: \ |
| + typedef c##Interface C; \ |
| + c##ProxyWithInternal(rtc::Thread* signaling_thread, \ |
| + rtc::Thread* worker_thread, \ |
| + INTERNAL_CLASS* c) \ |
| + : signaling_thread_(signaling_thread), \ |
| + worker_thread_(worker_thread), \ |
| + c_(c) {} \ |
| + \ |
| + public: \ |
| + ~c##ProxyWithInternal() { \ |
| + MethodCall0<c##ProxyWithInternal, void> call( \ |
| + this, &c##ProxyWithInternal::ReleaseOnCorrectThread); \ |
| + call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
| + } \ |
| + \ |
| + static std::unique_ptr<c##ProxyWithInternal> Create( \ |
| + rtc::Thread* signaling_thread, \ |
| + rtc::Thread* worker_thread, \ |
| + INTERNAL_CLASS* c) { \ |
| + return std::unique_ptr<c##ProxyWithInternal>( \ |
| + new c##ProxyWithInternal(signaling_thread, worker_thread, c)); \ |
| + } \ |
| + const INTERNAL_CLASS* internal() const { return c_.get(); } \ |
| + INTERNAL_CLASS* internal() { return c_.get(); } |
| + |
| +// Object that should be destroyed on the worker thread. |
| +#define BEGIN_NON_REFCOUNTED_WORKER_PROXY_MAP(c) \ |
| + template <class INTERNAL_CLASS> \ |
| + class c##ProxyWithInternal; \ |
| + typedef c##ProxyWithInternal<c##Interface> c##Proxy; \ |
| + template <class INTERNAL_CLASS> \ |
| + class c##ProxyWithInternal : public c##Interface { \ |
| + protected: \ |
| + typedef c##Interface C; \ |
| + c##ProxyWithInternal(rtc::Thread* signaling_thread, \ |
| + rtc::Thread* worker_thread, \ |
| + INTERNAL_CLASS* c) \ |
| + : signaling_thread_(signaling_thread), \ |
| + worker_thread_(worker_thread), \ |
| + c_(c) {} \ |
| + \ |
| + public: \ |
| + ~c##ProxyWithInternal() { \ |
| + MethodCall0<c##ProxyWithInternal, void> call( \ |
| + this, &c##ProxyWithInternal::ReleaseOnCorrectThread); \ |
| + call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| + } \ |
| + \ |
| + static std::unique_ptr<c##ProxyWithInternal> Create( \ |
| + rtc::Thread* signaling_thread, \ |
| + rtc::Thread* worker_thread, \ |
| + INTERNAL_CLASS* c) { \ |
| + return std::unique_ptr<c##ProxyWithInternal>( \ |
| + new c##ProxyWithInternal(signaling_thread, worker_thread, c)); \ |
| + } \ |
| + const INTERNAL_CLASS* internal() const { return c_.get(); } \ |
| + INTERNAL_CLASS* internal() { return c_.get(); } |
| + |
| #define PROXY_METHOD0(r, method) \ |
| r method() override { \ |
| MethodCall0<C, r> call(c_.get(), &C::method); \ |
| @@ -414,33 +479,66 @@ class MethodCall5 : public rtc::Message, |
| } |
| // Define methods which should be invoked on the worker thread. |
| +#define PROXY_WORKER_METHOD0(r, method) \ |
| + r method() override { \ |
| + MethodCall0<C, r> call(c_.get(), &C::method); \ |
| + return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| + } |
| + |
| +#define PROXY_WORKER_CONSTMETHOD0(r, method) \ |
| + r method() const override { \ |
| + ConstMethodCall0<C, r> call(c_.get(), &C::method); \ |
| + return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| + } |
| + |
| #define PROXY_WORKER_METHOD1(r, method, t1) \ |
| r method(t1 a1) override { \ |
| MethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \ |
| return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| } |
| +#define PROXY_WORKER_CONSTMETHOD1(r, method, t1) \ |
| + r method(t1 a1) const override { \ |
| + ConstMethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \ |
| + return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| + } |
| + |
| #define PROXY_WORKER_METHOD2(r, method, t1, t2) \ |
| r method(t1 a1, t2 a2) override { \ |
| MethodCall2<C, r, t1, t2> call(c_.get(), &C::method, a1, a2); \ |
| return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| } |
| -#define END_SIGNALING_PROXY() \ |
| - private: \ |
| - void Release_s() { c_ = NULL; } \ |
| - mutable rtc::Thread* signaling_thread_; \ |
| - rtc::scoped_refptr<INTERNAL_CLASS> c_; \ |
| - } \ |
| +#define PROXY_WORKER_CONSTMETHOD2(r, method, t1, t2) \ |
| + r method(t1 a1, t2 a2) const override { \ |
| + ConstMethodCall2<C, r, t1, t2> call(c_.get(), &C::method, a1, a2); \ |
| + return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| + } |
| + |
| +#define END_SIGNALING_PROXY() \ |
| + private: \ |
| + void ReleaseOnCorrectThread() { c_ = NULL; } \ |
| + mutable rtc::Thread* signaling_thread_; \ |
| + rtc::scoped_refptr<INTERNAL_CLASS> c_; \ |
| + } \ |
| + ; |
| + |
| +#define END_PROXY() \ |
| + private: \ |
| + void ReleaseOnCorrectThread() { c_ = NULL; } \ |
| + mutable rtc::Thread* signaling_thread_; \ |
| + mutable rtc::Thread* worker_thread_; \ |
| + rtc::scoped_refptr<INTERNAL_CLASS> c_; \ |
| + } \ |
| ; |
| -#define END_PROXY() \ |
| - private: \ |
| - void Release_s() { c_ = NULL; } \ |
| - mutable rtc::Thread* signaling_thread_; \ |
| - mutable rtc::Thread* worker_thread_; \ |
| - rtc::scoped_refptr<INTERNAL_CLASS> c_; \ |
| - } \ |
| +#define END_NON_REFCOUNTED_PROXY() \ |
| + private: \ |
| + void ReleaseOnCorrectThread() { c_.reset(nullptr); } \ |
| + mutable rtc::Thread* signaling_thread_; \ |
| + mutable rtc::Thread* worker_thread_; \ |
| + std::unique_ptr<INTERNAL_CLASS> c_; \ |
| + } \ |
| ; |
| } // namespace webrtc |