fix: Emplace MDConsumerHandle instead of copy assign
This commit is contained in:
1 parent
a51b015907
commit
797ba111ec
2 files changed
+37
-12
No files matched your search
@@ -114,11 +114,24 @@ class HandleIndex {
|
||||
LOG(md, Diag,
|
||||
"PositionService::HandleIndex::on_security security:{}",
|
||||
bts::securities::descriptor(*sec));
|
||||
if (_consumer->id() == id) {
|
||||
index.lock([handle](auto &index) {
|
||||
index[SecurityKey(handle.key())] = handle;
|
||||
});
|
||||
if (_consumer->id() != id) {
|
||||
return;
|
||||
}
|
||||
index.lock(
|
||||
[handle](std::unordered_map<SecurityKey, MDConsumerHandle>
|
||||
&index) {
|
||||
SecurityKey sec_key{handle.key()};
|
||||
if (index.find(sec_key) != index.end()) {
|
||||
return;
|
||||
}
|
||||
auto [_, is_new] =
|
||||
index.try_emplace(sec_key, std::move(handle));
|
||||
if (is_new) {
|
||||
LOG(md, Info,
|
||||
"MBOServiceServer added synthetic security: {}",
|
||||
*sec_key);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,14 +55,26 @@ class HandleIndex {
|
||||
}
|
||||
// Subscribe to on_security
|
||||
auto id = _consumer->id();
|
||||
_consumer->on_security(
|
||||
[this, id](const SecurityPtr &, MDConsumerHandle handle) {
|
||||
if (_consumer->id() == id) {
|
||||
index.lock([handle](auto &index) {
|
||||
index[SecurityKey(handle.key())] = handle;
|
||||
});
|
||||
}
|
||||
});
|
||||
_consumer->on_security([this, id](
|
||||
const SecurityPtr &,
|
||||
MDConsumerHandle handle) {
|
||||
if (_consumer->id() != id) {
|
||||
return;
|
||||
}
|
||||
index.lock(
|
||||
[handle](
|
||||
std::unordered_map<SecurityKey, MDConsumerHandle> &index) {
|
||||
SecurityKey sec_key{handle.key()};
|
||||
if (index.find(sec_key) != index.end()) {
|
||||
return;
|
||||
}
|
||||
auto [_, is_new] =
|
||||
index.try_emplace(sec_key, std::move(handle));
|
||||
if (is_new) {
|
||||
LOG(md, Info, "MBOServiceServer added security: {}", *sec_key);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user