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 #include "src/base/platform/semaphore.h" | 5 #include "src/base/platform/semaphore.h" |
6 | 6 |
7 #if V8_OS_MACOSX | 7 #if V8_OS_MACOSX |
8 #include <mach/mach_init.h> | 8 #include <mach/mach_init.h> |
9 #include <mach/task.h> | 9 #include <mach/task.h> |
10 #endif | 10 #endif |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 | 95 |
96 Semaphore::~Semaphore() { | 96 Semaphore::~Semaphore() { |
97 int result = sem_destroy(&native_handle_); | 97 int result = sem_destroy(&native_handle_); |
98 DCHECK_EQ(0, result); | 98 DCHECK_EQ(0, result); |
99 USE(result); | 99 USE(result); |
100 } | 100 } |
101 | 101 |
102 void Semaphore::Signal() { | 102 void Semaphore::Signal() { |
103 int result = sem_post(&native_handle_); | 103 int result = sem_post(&native_handle_); |
| 104 // This check may fail with <libc-2.21, which we use on the try bots, if the |
| 105 // semaphore is destroyed while sem_post is still executed. A work around is |
| 106 // to extend the lifetime of the semaphore. |
104 CHECK_EQ(0, result); | 107 CHECK_EQ(0, result); |
105 } | 108 } |
106 | 109 |
107 | 110 |
108 void Semaphore::Wait() { | 111 void Semaphore::Wait() { |
109 while (true) { | 112 while (true) { |
110 int result = sem_wait(&native_handle_); | 113 int result = sem_wait(&native_handle_); |
111 if (result == 0) return; // Semaphore was signalled. | 114 if (result == 0) return; // Semaphore was signalled. |
112 // Signal caused spurious wakeup. | 115 // Signal caused spurious wakeup. |
113 DCHECK_EQ(-1, result); | 116 DCHECK_EQ(-1, result); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 DCHECK(result == WAIT_OBJECT_0); | 208 DCHECK(result == WAIT_OBJECT_0); |
206 return true; | 209 return true; |
207 } | 210 } |
208 } | 211 } |
209 } | 212 } |
210 | 213 |
211 #endif // V8_OS_MACOSX | 214 #endif // V8_OS_MACOSX |
212 | 215 |
213 } // namespace base | 216 } // namespace base |
214 } // namespace v8 | 217 } // namespace v8 |
OLD | NEW |