| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 105 } |
| 106 | 106 |
| 107 | 107 |
| 108 bool Semaphore::WaitFor(const TimeDelta& rel_time) { | 108 bool Semaphore::WaitFor(const TimeDelta& rel_time) { |
| 109 // Compute the time for end of timeout. | 109 // Compute the time for end of timeout. |
| 110 const Time time = Time::NowFromSystemTime() + rel_time; | 110 const Time time = Time::NowFromSystemTime() + rel_time; |
| 111 const struct timespec ts = time.ToTimespec(); | 111 const struct timespec ts = time.ToTimespec(); |
| 112 | 112 |
| 113 // Wait for semaphore signalled or timeout. | 113 // Wait for semaphore signalled or timeout. |
| 114 while (true) { | 114 while (true) { |
| 115 #if V8_OS_NACL |
| 116 int result = sem_wait(&native_handle_); |
| 117 USE(ts); |
| 118 #else |
| 115 int result = sem_timedwait(&native_handle_, &ts); | 119 int result = sem_timedwait(&native_handle_, &ts); |
| 120 #endif |
| 116 if (result == 0) return true; // Semaphore was signalled. | 121 if (result == 0) return true; // Semaphore was signalled. |
| 117 #if V8_LIBC_GLIBC && !V8_GLIBC_PREREQ(2, 4) | 122 #if V8_LIBC_GLIBC && !V8_GLIBC_PREREQ(2, 4) |
| 118 if (result > 0) { | 123 if (result > 0) { |
| 119 // sem_timedwait in glibc prior to 2.3.4 returns the errno instead of -1. | 124 // sem_timedwait in glibc prior to 2.3.4 returns the errno instead of -1. |
| 120 errno = result; | 125 errno = result; |
| 121 result = -1; | 126 result = -1; |
| 122 } | 127 } |
| 123 #endif | 128 #endif |
| 124 if (result == -1 && errno == ETIMEDOUT) { | 129 if (result == -1 && errno == ETIMEDOUT) { |
| 125 // Timed out while waiting for semaphore. | 130 // Timed out while waiting for semaphore. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 } | 187 } |
| 183 DCHECK(result == WAIT_OBJECT_0); | 188 DCHECK(result == WAIT_OBJECT_0); |
| 184 return true; | 189 return true; |
| 185 } | 190 } |
| 186 } | 191 } |
| 187 } | 192 } |
| 188 | 193 |
| 189 #endif // V8_OS_MACOSX | 194 #endif // V8_OS_MACOSX |
| 190 | 195 |
| 191 } } // namespace v8::base | 196 } } // namespace v8::base |
| OLD | NEW |