Use precise memory orderings in load_tester
This commit is contained in:
@@ -401,6 +401,7 @@ private:
|
|||||||
double current_min = g_min_latency.load(std::memory_order_relaxed);
|
double current_min = g_min_latency.load(std::memory_order_relaxed);
|
||||||
while (latency < current_min &&
|
while (latency < current_min &&
|
||||||
!g_min_latency.compare_exchange_weak(current_min, latency,
|
!g_min_latency.compare_exchange_weak(current_min, latency,
|
||||||
|
std::memory_order_relaxed,
|
||||||
std::memory_order_relaxed)) {
|
std::memory_order_relaxed)) {
|
||||||
// Retry if another thread updated min_latency
|
// Retry if another thread updated min_latency
|
||||||
}
|
}
|
||||||
@@ -408,6 +409,7 @@ private:
|
|||||||
double current_max = g_max_latency.load(std::memory_order_relaxed);
|
double current_max = g_max_latency.load(std::memory_order_relaxed);
|
||||||
while (latency > current_max &&
|
while (latency > current_max &&
|
||||||
!g_max_latency.compare_exchange_weak(current_max, latency,
|
!g_max_latency.compare_exchange_weak(current_max, latency,
|
||||||
|
std::memory_order_relaxed,
|
||||||
std::memory_order_relaxed)) {
|
std::memory_order_relaxed)) {
|
||||||
// Retry if another thread updated max_latency
|
// Retry if another thread updated max_latency
|
||||||
}
|
}
|
||||||
@@ -637,7 +639,7 @@ int main(int argc, char *argv[]) {
|
|||||||
int epollfd = g_epoll_fds[i]; // Each thread uses its own epoll instance
|
int epollfd = g_epoll_fds[i]; // Each thread uses its own epoll instance
|
||||||
pthread_setname_np(pthread_self(),
|
pthread_setname_np(pthread_self(),
|
||||||
("network-" + std::to_string(i)).c_str());
|
("network-" + std::to_string(i)).c_str());
|
||||||
while (g_connect_threads.load() != 0) {
|
while (g_connect_threads.load(std::memory_order_acquire) != 0) {
|
||||||
struct epoll_event events[256]; // Use a reasonable max size
|
struct epoll_event events[256]; // Use a reasonable max size
|
||||||
int batch_size = std::min(int(sizeof(events) / sizeof(events[0])),
|
int batch_size = std::min(int(sizeof(events) / sizeof(events[0])),
|
||||||
g_config.event_batch_size);
|
g_config.event_batch_size);
|
||||||
@@ -779,7 +781,7 @@ int main(int argc, char *argv[]) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_connect_threads.fetch_sub(1);
|
g_connect_threads.fetch_sub(1, std::memory_order_release);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user