[Base] Use disruptorplus spin wait
- Attempt to fix deadlocks when using valgrind on CI
This commit is contained in:
parent
e59a0e1206
commit
3b4dc7da3b
|
@ -14,6 +14,8 @@
|
||||||
#define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
|
#define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
|
||||||
#include "third_party/catch/include/catch.hpp"
|
#include "third_party/catch/include/catch.hpp"
|
||||||
|
|
||||||
|
#include "third_party/disruptorplus/include/disruptorplus/spin_wait.hpp"
|
||||||
|
|
||||||
namespace xe {
|
namespace xe {
|
||||||
namespace base {
|
namespace base {
|
||||||
namespace test {
|
namespace test {
|
||||||
|
@ -25,12 +27,12 @@ template <class Clock, class Duration, class Predicate>
|
||||||
bool spin_wait_until(
|
bool spin_wait_until(
|
||||||
const std::chrono::time_point<Clock, Duration>& timeout_time,
|
const std::chrono::time_point<Clock, Duration>& timeout_time,
|
||||||
Predicate stop_waiting) {
|
Predicate stop_waiting) {
|
||||||
|
disruptorplus::spin_wait spinner;
|
||||||
while (!stop_waiting()) {
|
while (!stop_waiting()) {
|
||||||
if (std::chrono::steady_clock::now() >= timeout_time) {
|
if (std::chrono::steady_clock::now() >= timeout_time) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Needed for valgrind because it basically runs one thread:
|
spinner.spin_once();
|
||||||
MaybeYield();
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -43,9 +45,9 @@ bool spin_wait_for(const std::chrono::duration<Rep, Period>& rel_time,
|
||||||
|
|
||||||
template <class Predicate>
|
template <class Predicate>
|
||||||
void spin_wait(Predicate stop_waiting) {
|
void spin_wait(Predicate stop_waiting) {
|
||||||
|
disruptorplus::spin_wait spinner;
|
||||||
while (!stop_waiting()) {
|
while (!stop_waiting()) {
|
||||||
// Needed for valgrind because it basically runs one thread:
|
spinner.spin_once();
|
||||||
MaybeYield();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue