| 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/base-export.h" | |
| 9 #include "src/base/lazy-instance.h" | 8 #include "src/base/lazy-instance.h" |
| 10 #if V8_OS_WIN | 9 #if V8_OS_WIN |
| 11 #include "src/base/win32-headers.h" | 10 #include "src/base/win32-headers.h" |
| 12 #endif | 11 #endif |
| 13 | 12 |
| 14 #if V8_OS_MACOSX | 13 #if V8_OS_MACOSX |
| 15 #include <mach/semaphore.h> // NOLINT | 14 #include <mach/semaphore.h> // NOLINT |
| 16 #elif V8_OS_POSIX | 15 #elif V8_OS_POSIX |
| 17 #include <semaphore.h> // NOLINT | 16 #include <semaphore.h> // NOLINT |
| 18 #endif | 17 #endif |
| 19 | 18 |
| 20 namespace v8 { | 19 namespace v8 { |
| 21 namespace base { | 20 namespace base { |
| 22 | 21 |
| 23 // Forward declarations. | 22 // Forward declarations. |
| 24 class TimeDelta; | 23 class TimeDelta; |
| 25 | 24 |
| 26 // ---------------------------------------------------------------------------- | 25 // ---------------------------------------------------------------------------- |
| 27 // Semaphore | 26 // Semaphore |
| 28 // | 27 // |
| 29 // 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 |
| 30 // 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 |
| 31 // 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 |
| 32 // count reaches zero, threads waiting for the semaphore blocks until the | 31 // count reaches zero, threads waiting for the semaphore blocks until the |
| 33 // count becomes non-zero. | 32 // count becomes non-zero. |
| 34 | 33 |
| 35 class V8_BASE_EXPORT Semaphore final { | 34 class Semaphore final { |
| 36 public: | 35 public: |
| 37 explicit Semaphore(int count); | 36 explicit Semaphore(int count); |
| 38 ~Semaphore(); | 37 ~Semaphore(); |
| 39 | 38 |
| 40 // Increments the semaphore counter. | 39 // Increments the semaphore counter. |
| 41 void Signal(); | 40 void Signal(); |
| 42 | 41 |
| 43 // Decrements the semaphore counter if it is positive, or blocks until it | 42 // Decrements the semaphore counter if it is positive, or blocks until it |
| 44 // becomes positive and then decrements the counter. | 43 // becomes positive and then decrements the counter. |
| 45 void Wait(); | 44 void Wait(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 typedef typename LazyDynamicInstance<Semaphore, CreateSemaphoreTrait<N>, | 92 typedef typename LazyDynamicInstance<Semaphore, CreateSemaphoreTrait<N>, |
| 94 ThreadSafeInitOnceTrait>::type type; | 93 ThreadSafeInitOnceTrait>::type type; |
| 95 }; | 94 }; |
| 96 | 95 |
| 97 #define LAZY_SEMAPHORE_INITIALIZER LAZY_DYNAMIC_INSTANCE_INITIALIZER | 96 #define LAZY_SEMAPHORE_INITIALIZER LAZY_DYNAMIC_INSTANCE_INITIALIZER |
| 98 | 97 |
| 99 } // namespace base | 98 } // namespace base |
| 100 } // namespace v8 | 99 } // namespace v8 |
| 101 | 100 |
| 102 #endif // V8_BASE_PLATFORM_SEMAPHORE_H_ | 101 #endif // V8_BASE_PLATFORM_SEMAPHORE_H_ |
| OLD | NEW |