OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // | 2 // |
3 // Tests of the TokenLock class from lock.h | 3 // Tests of the TokenLock class from lock.h |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include "v8.h" | 7 #include "v8.h" |
8 | 8 |
9 #include "platform.h" | 9 #include "platform.h" |
10 #include "cctest.h" | 10 #include "cctest.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 | 32 |
33 TEST(ShallowLock) { | 33 TEST(ShallowLock) { |
34 Mutex* mutex = OS::CreateMutex(); | 34 Mutex* mutex = OS::CreateMutex(); |
35 CHECK_EQ(0, mutex->Lock()); | 35 CHECK_EQ(0, mutex->Lock()); |
36 CHECK_EQ(0, mutex->Unlock()); | 36 CHECK_EQ(0, mutex->Unlock()); |
37 CHECK_EQ(0, mutex->Lock()); | 37 CHECK_EQ(0, mutex->Lock()); |
38 CHECK_EQ(0, mutex->Unlock()); | 38 CHECK_EQ(0, mutex->Unlock()); |
39 delete mutex; | 39 delete mutex; |
40 } | 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 } |
OLD | NEW |