post() with const ref.
Added "safety" of passing move-able reference is an illusion since no use_count()==1 test is done. Instead extra (shallow) copies were made for each subscriber. Instead. Pass const reference, redefine MonitorControlOp::post() to transfer ownership, and make only a single copy in SharedPV::post().
This commit is contained in:
+8
-3
@@ -69,7 +69,7 @@ SharedPV SharedPV::buildMailbox()
|
||||
}
|
||||
}
|
||||
|
||||
pv.post(std::move(val));
|
||||
pv.post(val);
|
||||
|
||||
op->reply();
|
||||
});
|
||||
@@ -381,7 +381,7 @@ void SharedPV::close()
|
||||
}
|
||||
}
|
||||
|
||||
void SharedPV::post(Value&& val)
|
||||
void SharedPV::post(const Value& val)
|
||||
{
|
||||
if(!impl)
|
||||
throw std::logic_error("Empty SharedPV");
|
||||
@@ -397,8 +397,13 @@ void SharedPV::post(Value&& val)
|
||||
|
||||
impl->current.assign(val);
|
||||
|
||||
if(impl->subscribers.empty())
|
||||
return;
|
||||
|
||||
auto copy(val.clone());
|
||||
|
||||
for(auto& sub : impl->subscribers) {
|
||||
sub->post(val.clone());
|
||||
sub->post(copy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user