20 #include "gtest/gtest.h" 33 int running_thread_count
GUARDED_BY(counters_mu) = 0;
34 int call_once_invoke_count
GUARDED_BY(counters_mu) = 0;
35 int call_once_finished_count
GUARDED_BY(counters_mu) = 0;
36 int call_once_return_count
GUARDED_BY(counters_mu) = 0;
37 bool done_blocking
GUARDED_BY(counters_mu) =
false;
40 void WaitAndIncrement() {
42 ++call_once_invoke_count;
45 counters_mu.LockWhen(Condition(&done_blocking));
46 ++call_once_finished_count;
52 ++running_thread_count;
58 ++call_once_return_count;
65 return running_thread_count == 10 && call_once_invoke_count == 1;
68 TEST(CallOnceTest, ExecutionCount) {
69 std::vector<std::thread> threads;
72 for (
int i = 0;
i < 10; ++
i) {
73 threads.emplace_back(ThreadBody);
79 counters_mu.LockWhen(Condition(ThreadsAreSetup,
nullptr));
84 EXPECT_EQ(call_once_invoke_count, 1);
85 EXPECT_EQ(call_once_finished_count, 0);
86 EXPECT_EQ(call_once_return_count, 0);
93 for (std::thread& thread : threads) {
98 EXPECT_EQ(call_once_invoke_count, 1);
99 EXPECT_EQ(call_once_finished_count, 1);
100 EXPECT_EQ(call_once_return_count, 10);
101 counters_mu.Unlock();
#define EXCLUSIVE_LOCKS_REQUIRED(...)
TEST(NotificationTest, SanityTest)
void call_once(absl::once_flag &flag, Callable &&fn, Args &&... args)
struct absl::SynchWaitParams GUARDED_BY[kNSynchEvent]