maybe no atomic on active?

This commit is contained in:
Artur Mukhamadiev 2025-06-23 00:07:24 +03:00
parent 604a5e46c6
commit b958d407f1
2 changed files with 4 additions and 0 deletions

View File

@ -34,6 +34,7 @@ class Logger {
typename = std::enable_if_t<std::is_arithmetic_v<Metric>>> typename = std::enable_if_t<std::is_arithmetic_v<Metric>>>
void add(const std::string& field, Metric metric) { void add(const std::string& field, Metric metric) {
auto locked = active.load(); auto locked = active.load();
// auto locked = active;
auto it = locked->find(field); auto it = locked->find(field);
if (it == locked->end()) { if (it == locked->end()) {
throw configErrorMsg; throw configErrorMsg;
@ -50,6 +51,7 @@ class Logger {
std::unique_ptr<Worker> worker; std::unique_ptr<Worker> worker;
std::shared_ptr<map_type> m1, m2; std::shared_ptr<map_type> m1, m2;
std::atomic<std::shared_ptr<map_type>> active; // impl may use mutex! std::atomic<std::shared_ptr<map_type>> active; // impl may use mutex!
// std::shared_ptr<map_type> active;
}; };
} // namespace vptyp } // namespace vptyp

View File

@ -62,10 +62,12 @@ void Logger::Worker::unroll() {
return; return;
auto tmp = parent.active.load(); auto tmp = parent.active.load();
// auto tmp = parent.active;
auto toBeActive = tmp == parent.m1 ? parent.m2 : parent.m1; auto toBeActive = tmp == parent.m1 ? parent.m2 : parent.m1;
while (!parent.active.compare_exchange_weak(tmp, toBeActive)) { while (!parent.active.compare_exchange_weak(tmp, toBeActive)) {
std::this_thread::yield(); std::this_thread::yield();
} }
// parent.active = toBeActive;
while (tmp.use_count() > 2) { while (tmp.use_count() > 2) {
std::this_thread::yield(); std::this_thread::yield();