The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / v8 / test / cctest / test-lock.cc @ 40c0f755

History | View | Annotate | Download (1.19 KB)

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

    
5
#include <stdlib.h>
6

    
7
#include "v8.h"
8

    
9
#include "platform.h"
10
#include "cctest.h"
11

    
12

    
13
using namespace ::v8::internal;
14

    
15

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

    
24

    
25
TEST(MultiLock) {
26
  Mutex* mutex = OS::CreateMutex();
27
  CHECK_EQ(0, mutex->Lock());
28
  CHECK_EQ(0, mutex->Unlock());
29
  delete mutex;
30
}
31

    
32

    
33
TEST(ShallowLock) {
34
  Mutex* mutex = OS::CreateMutex();
35
  CHECK_EQ(0, mutex->Lock());
36
  CHECK_EQ(0, mutex->Unlock());
37
  CHECK_EQ(0, mutex->Lock());
38
  CHECK_EQ(0, mutex->Unlock());
39
  delete mutex;
40
}
41

    
42

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

    
47
  // Semaphore not signalled - timeout.
48
  ok = sem->Wait(0);
49
  CHECK(!ok);
50
  ok = sem->Wait(100);
51
  CHECK(!ok);
52
  ok = sem->Wait(1000);
53
  CHECK(!ok);
54

    
55
  // Semaphore signalled - no timeout.
56
  sem->Signal();
57
  ok = sem->Wait(0);
58
  sem->Signal();
59
  ok = sem->Wait(100);
60
  sem->Signal();
61
  ok = sem->Wait(1000);
62
  CHECK(ok);
63
}