26 template <
bool MayBlock,
template <
typename>
class Atom = std::atomic>
35 f.
wait_options().spin_max(std::chrono::microseconds(1))));
49 template <
bool MayBlock,
template <
typename>
class Atom = std::atomic>
52 std::array<WF, 17>
flags;
56 for (
int i = 0;
i < numRounds; ++
i) {
63 for (
int i = 0;
i < numRounds; ++
i) {
72 template <
bool MayBlock,
template <
typename>
class Atom = std::atomic>
75 std::atomic<int> posted{0};
76 std::atomic<int> waited{0};
77 std::atomic<bool> go_post{
false};
78 std::atomic<bool> go_wait{
false};
80 std::vector<std::thread> prod(np);
81 std::vector<std::thread> cons(nw);
82 for (
int i = 0;
i < np; ++
i) {
84 while (!go_post.load()) {
92 for (
int i = 0;
i < nw; ++
i) {
101 f.
wait_options().spin_max(std::chrono::microseconds(0))));
103 while (!go_wait.load()) {
113 f.
wait_options().spin_max(std::chrono::microseconds(0))));
118 while (waited.load() < nw) {
122 while (posted.load() < np) {
127 for (
auto&
t : prod) {
130 for (
auto&
t : cons) {
138 run_basic_test<false>();
142 run_basic_test<true>();
146 run_pingpong_test<false>(1000);
150 run_pingpong_test<true>(1000);
154 run_multi_poster_multi_waiter_test<false>(1, 1);
155 run_multi_poster_multi_waiter_test<false>(1, 10);
156 run_multi_poster_multi_waiter_test<false>(10, 1);
157 run_multi_poster_multi_waiter_test<false>(10, 10);
161 run_multi_poster_multi_waiter_test<true>(1, 1);
162 run_multi_poster_multi_waiter_test<true>(1, 10);
163 run_multi_poster_multi_waiter_test<true>(10, 1);
164 run_multi_poster_multi_waiter_test<true>(10, 10);
FOLLY_ALWAYS_INLINE bool ready() const noexcept
FOLLY_ALWAYS_INLINE void wait(const WaitOptions &opt=wait_options()) noexcept
void run_multi_poster_multi_waiter_test(int np, int nw)
TEST(SaturatingSemaphore, basic_spin_only)
Tests.
std::chrono::steady_clock::time_point now()
void run_pingpong_test(int numRounds)
static std::thread thread(Func &&func, Args &&...args)
static FOLLY_ALWAYS_INLINE WaitOptions wait_options()
FOLLY_ALWAYS_INLINE void post() noexcept
FOLLY_ALWAYS_INLINE bool try_wait_until(const std::chrono::time_point< Clock, Duration > &deadline, const WaitOptions &opt=wait_options()) noexcept
FOLLY_ALWAYS_INLINE bool try_wait_for(const std::chrono::duration< Rep, Period > &duration, const WaitOptions &opt=wait_options()) noexcept
FOLLY_ALWAYS_INLINE bool try_wait() noexcept
#define ASSERT_FALSE(condition)
static void join(std::thread &child)
#define ASSERT_TRUE(condition)