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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 #elif V8_OS_POSIX | 73 #elif V8_OS_POSIX |
74 | 74 |
75 Semaphore::Semaphore(int count) { | 75 Semaphore::Semaphore(int count) { |
76 // The sem_init() does not check for alignment of the native handle. | 76 // The sem_init() does not check for alignment of the native handle. |
77 // Unaligned native handle can later cause a failure in semaphore signal. | 77 // Unaligned native handle can later cause a failure in semaphore signal. |
78 // Check the alignment here to catch the failure earlier. | 78 // Check the alignment here to catch the failure earlier. |
79 // Context: crbug.com/605349. | 79 // Context: crbug.com/605349. |
80 #if V8_OS_AIX | 80 #if V8_OS_AIX || V8_OS_FREEBSD |
81 // On aix sem_t is of type int | 81 // On aix sem_t is of type int. On FreeBSD, it's a struct of 32 bits fields. |
82 const uintptr_t kSemaphoreAlignmentMask = sizeof(int) - 1; | 82 const uintptr_t kSemaphoreAlignmentMask = sizeof(int) - 1; |
83 #else | 83 #else |
84 const uintptr_t kSemaphoreAlignmentMask = sizeof(void*) - 1; | 84 const uintptr_t kSemaphoreAlignmentMask = sizeof(void*) - 1; |
85 #endif | 85 #endif |
86 CHECK_EQ( | 86 CHECK_EQ( |
87 0, reinterpret_cast<uintptr_t>(&native_handle_) & | 87 0, reinterpret_cast<uintptr_t>(&native_handle_) & |
88 kSemaphoreAlignmentMask); | 88 kSemaphoreAlignmentMask); |
89 DCHECK(count >= 0); | 89 DCHECK(count >= 0); |
90 int result = sem_init(&native_handle_, 0, count); | 90 int result = sem_init(&native_handle_, 0, count); |
91 DCHECK_EQ(0, result); | 91 DCHECK_EQ(0, result); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 DCHECK(result == WAIT_OBJECT_0); | 196 DCHECK(result == WAIT_OBJECT_0); |
197 return true; | 197 return true; |
198 } | 198 } |
199 } | 199 } |
200 } | 200 } |
201 | 201 |
202 #endif // V8_OS_MACOSX | 202 #endif // V8_OS_MACOSX |
203 | 203 |
204 } // namespace base | 204 } // namespace base |
205 } // namespace v8 | 205 } // namespace v8 |
OLD | NEW |