36 using namespace ::v8::internal;
39 class WaitAndSignalThread
V8_FINAL :
public Thread {
42 : Thread(
"WaitAndSignalThread"), semaphore_(semaphore) {}
46 for (
int n = 0; n < 1000; ++n) {
48 bool result = semaphore_->WaitFor(TimeDelta::FromMicroseconds(1));
56 Semaphore* semaphore_;
62 WaitAndSignalThread t1(&semaphore);
63 WaitAndSignalThread t2(&semaphore);
76 bool result = semaphore.WaitFor(TimeDelta::FromMicroseconds(1));
87 ok = semaphore.WaitFor(TimeDelta::FromMicroseconds(0));
89 ok = semaphore.WaitFor(TimeDelta::FromMicroseconds(100));
91 ok = semaphore.WaitFor(TimeDelta::FromMicroseconds(1000));
96 ok = semaphore.WaitFor(TimeDelta::FromMicroseconds(0));
99 ok = semaphore.WaitFor(TimeDelta::FromMicroseconds(100));
102 ok = semaphore.WaitFor(TimeDelta::FromMicroseconds(1000));
107 static const char alphabet[] =
"XKOAD";
108 static const int kAlphabetSize =
sizeof(alphabet) - 1;
109 static const int kBufferSize = 4096;
110 static char buffer[kBufferSize];
111 static const int kDataSize = kBufferSize * kAlphabetSize * 10;
113 static Semaphore free_space(kBufferSize);
114 static Semaphore used_space(0);
117 class ProducerThread
V8_FINAL :
public Thread {
123 for (
int n = 0; n < kDataSize; ++n) {
125 buffer[n % kBufferSize] = alphabet[n % kAlphabetSize];
132 class ConsumerThread
V8_FINAL :
public Thread {
138 for (
int n = 0; n < kDataSize; ++n) {
140 ASSERT_EQ(static_cast<int>(alphabet[n % kAlphabetSize]),
141 static_cast<int>(buffer[n % kBufferSize]));
149 ProducerThread producer_thread;
150 ConsumerThread consumer_thread;
151 producer_thread.Start();
152 consumer_thread.Start();
153 producer_thread.Join();
154 consumer_thread.Join();
virtual ~WaitAndSignalThread()
#define ASSERT(condition)
virtual ~ProducerThread()
#define ASSERT_EQ(v1, v2)
WaitAndSignalThread(Semaphore *semaphore)
virtual void Run() V8_OVERRIDE
virtual ~ConsumerThread()
v8::internal::Semaphore * semaphore