Sha256: 0151d2fe8a0469f9fac321785848f82201ea667efe0067f9c5fa9f1c0aacc601

Contents?: true

Size: 1.19 KB

Versions: 13

Compression:

Stored size: 1.19 KB

Contents

// Copyright 2006-2008 the V8 project authors. All rights reserved.
//
// Tests of the TokenLock class from lock.h

#include <stdlib.h>

#include "v8.h"

#include "platform.h"
#include "cctest.h"


using namespace ::v8::internal;


// Simple test of locking logic
TEST(Simple) {
  Mutex* mutex = OS::CreateMutex();
  CHECK_EQ(0, mutex->Lock());  // acquire the lock with the right token
  CHECK_EQ(0, mutex->Unlock());  // can unlock with the right token
  delete mutex;
}


TEST(MultiLock) {
  Mutex* mutex = OS::CreateMutex();
  CHECK_EQ(0, mutex->Lock());
  CHECK_EQ(0, mutex->Unlock());
  delete mutex;
}


TEST(ShallowLock) {
  Mutex* mutex = OS::CreateMutex();
  CHECK_EQ(0, mutex->Lock());
  CHECK_EQ(0, mutex->Unlock());
  CHECK_EQ(0, mutex->Lock());
  CHECK_EQ(0, mutex->Unlock());
  delete mutex;
}


TEST(SemaphoreTimeout) {
  bool ok;
  Semaphore* sem = OS::CreateSemaphore(0);

  // Semaphore not signalled - timeout.
  ok = sem->Wait(0);
  CHECK(!ok);
  ok = sem->Wait(100);
  CHECK(!ok);
  ok = sem->Wait(1000);
  CHECK(!ok);

  // Semaphore signalled - no timeout.
  sem->Signal();
  ok = sem->Wait(0);
  sem->Signal();
  ok = sem->Wait(100);
  sem->Signal();
  ok = sem->Wait(1000);
  CHECK(ok);
}

Version data entries

13 entries across 11 versions & 3 rubygems

Version Path
rednode-0.1.2 ext/node/deps/v8/test/cctest/test-lock.cc
rednode-0.1.1 ext/node/deps/v8/test/cctest/test-lock.cc
rednode-0.1.0 ext/node/deps/v8/test/cctest/test-lock.cc
tomato-0.0.1.prealpha2 ext/tomato/external/build/v8/test/cctest/test-lock.cc
tomato-0.0.1.prealpha2 ext/tomato/external/v8/test/cctest/test-lock.cc
tomato-0.0.1.prealpha1 ext/tomato/external/build/v8/test/cctest/test-lock.cc
tomato-0.0.1.prealpha1 ext/tomato/external/v8/test/cctest/test-lock.cc
therubyracer-0.4.8-x86-darwin-9 ext/v8/upstream/2.0.6/test/cctest/test-lock.cc
therubyracer-0.4.8-x86-darwin-10 ext/v8/upstream/2.0.6/test/cctest/test-lock.cc
therubyracer-0.4.8 ext/v8/upstream/2.0.6/test/cctest/test-lock.cc
therubyracer-0.4.7-x86-darwin-9 ext/v8/upstream/2.0.6/test/cctest/test-lock.cc
therubyracer-0.4.7-x86-darwin-10 ext/v8/upstream/2.0.6/test/cctest/test-lock.cc
therubyracer-0.4.7 ext/v8/upstream/2.0.6/test/cctest/test-lock.cc