18 #include <condition_variable> 25 #include "gtest/gtest.h" 36 namespace synchronization_internal {
48 std::unique_lock<std::mutex> lock(
mu_);
49 cv_.wait(lock, [
this]() {
return count_ > 0; });
59 std::lock_guard<std::mutex> lock(
mu_);
66 std::condition_variable
cv_;
91 static const int kNumIterations = 100;
101 std::thread partner_thread(std::bind(TimingThread, &t));
106 int64_t min_cycles = std::numeric_limits<int64_t>::max();
107 int64_t total_cycles = 0;
108 for (
int i = 0;
i < kNumIterations; ++
i) {
114 min_cycles = std::min(min_cycles, cycles);
115 total_cycles += cycles;
118 msg,
"min cycle count=", min_cycles,
" avg cycle count=",
120 printf(
"%s\n", out.c_str());
122 partner_thread.join();
156 EXPECT_FALSE(
Wait(start + delay));
161 EXPECT_LE(delay - slop, elapsed)
162 <<
"Wait returned " << delay - elapsed
163 <<
" early (with " << slop <<
" slop), start time was " << start;
166 EXPECT_FALSE(
Wait(negative_timeout));
167 EXPECT_LE(negative_timeout,
absl::Now() + slop);
172 EXPECT_TRUE(
Wait(negative_timeout));
void SleepFor(absl::Duration duration)
void TestTiming(const char *msg, bool timeout)
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
base_internal::ThreadIdentity * GetOrCreateCurrentThreadIdentity()
static void Post(base_internal::ThreadIdentity *identity)
static KernelTimeout Never()
constexpr Duration Microseconds(int64_t n)
constexpr Duration Milliseconds(int64_t n)
base_internal::ThreadIdentity * identity2
strings_internal::AlphaNumBuffer< numbers_internal::kSixDigitsToBufferSize > SixDigits(double d)
static void TimingThread(ThreadData *t)
base_internal::ThreadIdentity * identity1
constexpr Time UnixEpoch()
static void Tick(base_internal::ThreadIdentity *identity)
static void Tick(base_internal::ThreadIdentity *identity)
TEST_F(GraphCyclesTest, NoCycle)
static bool Wait(KernelTimeout t)
SimpleSemaphore identity2_written
constexpr Duration Seconds(int64_t n)
static bool Wait(absl::Time t)
static void Post(base_internal::ThreadIdentity *id)
std::condition_variable cv_
static bool Wait(KernelTimeout t)