10 #include "testing/gtest/include/gtest/gtest.h"
28 free_space_(free_space),
29 used_space_(used_space) {}
36 used_space_->Signal();
50 Semaphore* used_space)
53 free_space_(free_space),
54 used_space_(used_space) {}
61 free_space_->Signal();
67 Semaphore*
const free_space_;
68 Semaphore*
const used_space_;
75 :
Thread(
Options(
"WaitAndSignalThread")), semaphore_(semaphore) {}
79 for (
int n = 0; n < 100; ++n) {
81 ASSERT_FALSE(semaphore_->WaitFor(TimeDelta::FromMicroseconds(1)));
93 TEST(Semaphore, ProducerConsumer) {
95 std::memset(buffer, 0,
sizeof(buffer));
97 Semaphore used_space(0);
98 ProducerThread producer_thread(buffer, &free_space, &used_space);
99 ConsumerThread consumer_thread(buffer, &free_space, &used_space);
100 producer_thread.Start();
101 consumer_thread.Start();
102 producer_thread.Join();
103 consumer_thread.Join();
107 TEST(Semaphore, WaitAndSignal) {
108 Semaphore semaphore(0);
109 WaitAndSignalThread t1(&semaphore);
110 WaitAndSignalThread t2(&semaphore);
123 EXPECT_FALSE(semaphore.WaitFor(TimeDelta::FromMicroseconds(1)));
128 Semaphore semaphore(0);
131 ASSERT_FALSE(semaphore.WaitFor(TimeDelta::FromMicroseconds(0)));
132 ASSERT_FALSE(semaphore.WaitFor(TimeDelta::FromMicroseconds(100)));
133 ASSERT_FALSE(semaphore.WaitFor(TimeDelta::FromMicroseconds(1000)));
137 ASSERT_TRUE(semaphore.WaitFor(TimeDelta::FromMicroseconds(0)));
139 ASSERT_TRUE(semaphore.WaitFor(TimeDelta::FromMicroseconds(100)));
141 ASSERT_TRUE(semaphore.WaitFor(TimeDelta::FromMicroseconds(1000)));
Semaphore *const used_space_
virtual ~ProducerThread()
WaitAndSignalThread(Semaphore *semaphore)
ProducerThread(char *buffer, Semaphore *free_space, Semaphore *used_space)
Semaphore *const free_space_
virtual void Run() OVERRIDE
Semaphore *const semaphore_
virtual ~WaitAndSignalThread()
ConsumerThread(const char *buffer, Semaphore *free_space, Semaphore *used_space)
virtual ~ConsumerThread()
static const size_t kDataSize
static const char kAlphabet[]
static const size_t kAlphabetSize
static const size_t kBufferSize
TEST(CPUTest, FeatureImplications)
Debugger support for the V8 JavaScript engine.