| OLD | NEW | 
|---|
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef V8_BASE_PLATFORM_SEMAPHORE_H_ | 5 #ifndef V8_BASE_PLATFORM_SEMAPHORE_H_ | 
| 6 #define V8_BASE_PLATFORM_SEMAPHORE_H_ | 6 #define V8_BASE_PLATFORM_SEMAPHORE_H_ | 
| 7 | 7 | 
| 8 #include "src/base/lazy-instance.h" | 8 #include "src/base/lazy-instance.h" | 
| 9 #if V8_OS_WIN | 9 #if V8_OS_WIN | 
| 10 #include "src/base/win32-headers.h" | 10 #include "src/base/win32-headers.h" | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 24 | 24 | 
| 25 // ---------------------------------------------------------------------------- | 25 // ---------------------------------------------------------------------------- | 
| 26 // Semaphore | 26 // Semaphore | 
| 27 // | 27 // | 
| 28 // A semaphore object is a synchronization object that maintains a count. The | 28 // A semaphore object is a synchronization object that maintains a count. The | 
| 29 // count is decremented each time a thread completes a wait for the semaphore | 29 // count is decremented each time a thread completes a wait for the semaphore | 
| 30 // object and incremented each time a thread signals the semaphore. When the | 30 // object and incremented each time a thread signals the semaphore. When the | 
| 31 // count reaches zero,  threads waiting for the semaphore blocks until the | 31 // count reaches zero,  threads waiting for the semaphore blocks until the | 
| 32 // count becomes non-zero. | 32 // count becomes non-zero. | 
| 33 | 33 | 
| 34 class Semaphore V8_FINAL { | 34 class Semaphore FINAL { | 
| 35  public: | 35  public: | 
| 36   explicit Semaphore(int count); | 36   explicit Semaphore(int count); | 
| 37   ~Semaphore(); | 37   ~Semaphore(); | 
| 38 | 38 | 
| 39   // Increments the semaphore counter. | 39   // Increments the semaphore counter. | 
| 40   void Signal(); | 40   void Signal(); | 
| 41 | 41 | 
| 42   // Suspends the calling thread until the semaphore counter is non zero | 42   // Suspends the calling thread until the semaphore counter is non zero | 
| 43   // and then decrements the semaphore counter. | 43   // and then decrements the semaphore counter. | 
| 44   void Wait(); | 44   void Wait(); | 
| 45 | 45 | 
| 46   // Suspends the calling thread until the counter is non zero or the timeout | 46   // Suspends the calling thread until the counter is non zero or the timeout | 
| 47   // time has passed. If timeout happens the return value is false and the | 47   // time has passed. If timeout happens the return value is false and the | 
| 48   // counter is unchanged. Otherwise the semaphore counter is decremented and | 48   // counter is unchanged. Otherwise the semaphore counter is decremented and | 
| 49   // true is returned. | 49   // true is returned. | 
| 50   bool WaitFor(const TimeDelta& rel_time) V8_WARN_UNUSED_RESULT; | 50   bool WaitFor(const TimeDelta& rel_time) WARN_UNUSED_RESULT; | 
| 51 | 51 | 
| 52 #if V8_OS_MACOSX | 52 #if V8_OS_MACOSX | 
| 53   typedef semaphore_t NativeHandle; | 53   typedef semaphore_t NativeHandle; | 
| 54 #elif V8_OS_POSIX | 54 #elif V8_OS_POSIX | 
| 55   typedef sem_t NativeHandle; | 55   typedef sem_t NativeHandle; | 
| 56 #elif V8_OS_WIN | 56 #elif V8_OS_WIN | 
| 57   typedef HANDLE NativeHandle; | 57   typedef HANDLE NativeHandle; | 
| 58 #endif | 58 #endif | 
| 59 | 59 | 
| 60   NativeHandle& native_handle() { | 60   NativeHandle& native_handle() { | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 92 struct LazySemaphore { | 92 struct LazySemaphore { | 
| 93   typedef typename LazyDynamicInstance<Semaphore, CreateSemaphoreTrait<N>, | 93   typedef typename LazyDynamicInstance<Semaphore, CreateSemaphoreTrait<N>, | 
| 94                                        ThreadSafeInitOnceTrait>::type type; | 94                                        ThreadSafeInitOnceTrait>::type type; | 
| 95 }; | 95 }; | 
| 96 | 96 | 
| 97 #define LAZY_SEMAPHORE_INITIALIZER LAZY_DYNAMIC_INSTANCE_INITIALIZER | 97 #define LAZY_SEMAPHORE_INITIALIZER LAZY_DYNAMIC_INSTANCE_INITIALIZER | 
| 98 | 98 | 
| 99 } }  // namespace v8::base | 99 } }  // namespace v8::base | 
| 100 | 100 | 
| 101 #endif  // V8_BASE_PLATFORM_SEMAPHORE_H_ | 101 #endif  // V8_BASE_PLATFORM_SEMAPHORE_H_ | 
| OLD | NEW | 
|---|