Add ability to use movable only functors in rtc::Thread::Invoke(...)
Add support for movable only functors with void return type. Non void return type is already supported. Bug: webrtc:10138 Change-Id: If2ae2b5ab7244a0e932bceff7d9853c030805688 Reviewed-on: https://webrtc-review.googlesource.com/c/116740 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/master@{#26186}
This commit is contained in:
@ -520,9 +520,10 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
|
||||
class ScopedCallThread {
|
||||
public:
|
||||
template <class FunctorT>
|
||||
explicit ScopedCallThread(const FunctorT& functor)
|
||||
explicit ScopedCallThread(FunctorT&& functor)
|
||||
: thread_(rtc::Thread::Create()),
|
||||
task_(new rtc::FunctorMessageHandler<void, FunctorT>(functor)) {
|
||||
task_(new rtc::FunctorMessageHandler<void, FunctorT>(
|
||||
std::forward<FunctorT>(functor))) {
|
||||
thread_->Start();
|
||||
thread_->Post(RTC_FROM_HERE, task_.get());
|
||||
}
|
||||
|
@ -55,7 +55,8 @@ class FunctorMessageHandler : public MessageHandler {
|
||||
template <class FunctorT>
|
||||
class FunctorMessageHandler<void, FunctorT> : public MessageHandler {
|
||||
public:
|
||||
explicit FunctorMessageHandler(const FunctorT& functor) : functor_(functor) {}
|
||||
explicit FunctorMessageHandler(FunctorT&& functor)
|
||||
: functor_(std::forward<FunctorT>(functor)) {}
|
||||
virtual void OnMessage(Message* msg) { functor_(); }
|
||||
void result() const {}
|
||||
void MoveResult() {}
|
||||
|
@ -272,7 +272,7 @@ TEST(FakeClock, SettingTimeWakesThreads) {
|
||||
auto functor = [&message_handler_dispatched] {
|
||||
message_handler_dispatched.Set();
|
||||
};
|
||||
FunctorMessageHandler<void, decltype(functor)> handler(functor);
|
||||
FunctorMessageHandler<void, decltype(functor)> handler(std::move(functor));
|
||||
worker->PostDelayed(RTC_FROM_HERE, 60000, &handler);
|
||||
|
||||
// Wait for a bit for the worker thread to be started and enter its socket
|
||||
|
Reference in New Issue
Block a user