| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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. | 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. | 78 // Unaligned native handle can later cause a failure in semaphore signal. |
| 79 // Check the alignment here to catch the failure earlier. | 79 // Check the alignment here to catch the failure earlier. |
| 80 // Context: crbug.com/605349. | 80 // Context: crbug.com/605349. |
| 81 const uintptr_t kPointerAlignmentMask = sizeof(void*) - 1; | 81 #if V8_OS_AIX |
| 82 // On aix sem_t is of type int |
| 83 const uintptr_t kSemaphoreAlignmentMask = sizeof(int) - 1; |
| 84 #else |
| 85 const uintptr_t kSemaphoreAlignmentMask = sizeof(void*) - 1; |
| 86 #endif |
| 82 CHECK_EQ( | 87 CHECK_EQ( |
| 83 0, reinterpret_cast<uintptr_t>(&native_handle_) & kPointerAlignmentMask); | 88 0, reinterpret_cast<uintptr_t>(&native_handle_) & |
| 89 kSemaphoreAlignmentMask); |
| 84 DCHECK(count >= 0); | 90 DCHECK(count >= 0); |
| 85 #if V8_LIBC_GLIBC | 91 #if V8_LIBC_GLIBC |
| 86 // sem_init in glibc prior to 2.1 does not zero out semaphores. | 92 // sem_init in glibc prior to 2.1 does not zero out semaphores. |
| 87 memset(&native_handle_, 0, sizeof(native_handle_)); | 93 memset(&native_handle_, 0, sizeof(native_handle_)); |
| 88 #endif | 94 #endif |
| 89 int result = sem_init(&native_handle_, 0, count); | 95 int result = sem_init(&native_handle_, 0, count); |
| 90 DCHECK_EQ(0, result); | 96 DCHECK_EQ(0, result); |
| 91 USE(result); | 97 USE(result); |
| 92 } | 98 } |
| 93 | 99 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 DCHECK(result == WAIT_OBJECT_0); | 214 DCHECK(result == WAIT_OBJECT_0); |
| 209 return true; | 215 return true; |
| 210 } | 216 } |
| 211 } | 217 } |
| 212 } | 218 } |
| 213 | 219 |
| 214 #endif // V8_OS_MACOSX | 220 #endif // V8_OS_MACOSX |
| 215 | 221 |
| 216 } // namespace base | 222 } // namespace base |
| 217 } // namespace v8 | 223 } // namespace v8 |
| OLD | NEW |