maybe no atomic on active?
This commit is contained in:
parent
604a5e46c6
commit
b958d407f1
@ -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
|
||||||
@ -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();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user