| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 if (result == KERN_SUCCESS) return true; // Semaphore was signalled. | 67 if (result == KERN_SUCCESS) return true; // Semaphore was signalled. |
| 68 if (result == KERN_OPERATION_TIMED_OUT) return false; // Timeout. | 68 if (result == KERN_OPERATION_TIMED_OUT) return false; // Timeout. |
| 69 DCHECK_EQ(KERN_ABORTED, result); | 69 DCHECK_EQ(KERN_ABORTED, result); |
| 70 now = TimeTicks::Now(); | 70 now = TimeTicks::Now(); |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 #elif V8_OS_POSIX | 74 #elif V8_OS_POSIX |
| 75 | 75 |
| 76 Semaphore::Semaphore(int count) { | 76 Semaphore::Semaphore(int count) { |
| 77 // The sem_init() does not check for alignment of the native handle. | |
| 78 // Unaligned native handle can later cause a failure in semaphore signal. | |
| 79 // Check the alignment here to catch the failure earlier. | |
| 80 // Context: crbug.com/605349. | |
| 81 const uintptr_t kPointerAlignmentMask = sizeof(void*) - 1; | |
| 82 CHECK_EQ( | |
| 83 0, reinterpret_cast<uintptr_t>(&native_handle_) & kPointerAlignmentMask); | |
| 84 DCHECK(count >= 0); | 77 DCHECK(count >= 0); |
| 85 #if V8_LIBC_GLIBC | 78 #if V8_LIBC_GLIBC |
| 86 // sem_init in glibc prior to 2.1 does not zero out semaphores. | 79 // sem_init in glibc prior to 2.1 does not zero out semaphores. |
| 87 memset(&native_handle_, 0, sizeof(native_handle_)); | 80 memset(&native_handle_, 0, sizeof(native_handle_)); |
| 88 #endif | 81 #endif |
| 89 int result = sem_init(&native_handle_, 0, count); | 82 int result = sem_init(&native_handle_, 0, count); |
| 90 DCHECK_EQ(0, result); | 83 DCHECK_EQ(0, result); |
| 91 USE(result); | 84 USE(result); |
| 92 } | 85 } |
| 93 | 86 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 DCHECK(result == WAIT_OBJECT_0); | 199 DCHECK(result == WAIT_OBJECT_0); |
| 207 return true; | 200 return true; |
| 208 } | 201 } |
| 209 } | 202 } |
| 210 } | 203 } |
| 211 | 204 |
| 212 #endif // V8_OS_MACOSX | 205 #endif // V8_OS_MACOSX |
| 213 | 206 |
| 214 } // namespace base | 207 } // namespace base |
| 215 } // namespace v8 | 208 } // namespace v8 |
| OLD | NEW |