Chromium Code Reviews| 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.19, which we use on the try bots, if the | |
|
Michael Lippautz
2016/06/22 10:34:46
nit: Maybe just write that it fails for <libc-2.21
| |
| 105 // semaphore is destroyed while sem_post is still executed. A work around is | |
| 106 // to extend the lifetime of the semaphore. The problem got fixed in | |
| 107 // libc-2.21. | |
| 104 CHECK_EQ(0, result); | 108 CHECK_EQ(0, result); |
| 105 } | 109 } |
| 106 | 110 |
| 107 | 111 |
| 108 void Semaphore::Wait() { | 112 void Semaphore::Wait() { |
| 109 while (true) { | 113 while (true) { |
| 110 int result = sem_wait(&native_handle_); | 114 int result = sem_wait(&native_handle_); |
| 111 if (result == 0) return; // Semaphore was signalled. | 115 if (result == 0) return; // Semaphore was signalled. |
| 112 // Signal caused spurious wakeup. | 116 // Signal caused spurious wakeup. |
| 113 DCHECK_EQ(-1, result); | 117 DCHECK_EQ(-1, result); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 DCHECK(result == WAIT_OBJECT_0); | 209 DCHECK(result == WAIT_OBJECT_0); |
| 206 return true; | 210 return true; |
| 207 } | 211 } |
| 208 } | 212 } |
| 209 } | 213 } |
| 210 | 214 |
| 211 #endif // V8_OS_MACOSX | 215 #endif // V8_OS_MACOSX |
| 212 | 216 |
| 213 } // namespace base | 217 } // namespace base |
| 214 } // namespace v8 | 218 } // namespace v8 |
| OLD | NEW |