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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 DCHECK(count >= 0); | 77 DCHECK(count >= 0); |
| 78 #if V8_LIBC_GLIBC |
| 79 // sem_init in glibc prior to 2.1 does not zero out semaphores. |
| 80 memset(&native_handle_, 0, sizeof(native_handle_)); |
| 81 #endif |
78 int result = sem_init(&native_handle_, 0, count); | 82 int result = sem_init(&native_handle_, 0, count); |
79 DCHECK_EQ(0, result); | 83 DCHECK_EQ(0, result); |
80 USE(result); | 84 USE(result); |
81 } | 85 } |
82 | 86 |
83 | 87 |
84 Semaphore::~Semaphore() { | 88 Semaphore::~Semaphore() { |
85 int result = sem_destroy(&native_handle_); | 89 int result = sem_destroy(&native_handle_); |
86 DCHECK_EQ(0, result); | 90 DCHECK_EQ(0, result); |
87 USE(result); | 91 USE(result); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 DCHECK(result == WAIT_OBJECT_0); | 200 DCHECK(result == WAIT_OBJECT_0); |
197 return true; | 201 return true; |
198 } | 202 } |
199 } | 203 } |
200 } | 204 } |
201 | 205 |
202 #endif // V8_OS_MACOSX | 206 #endif // V8_OS_MACOSX |
203 | 207 |
204 } // namespace base | 208 } // namespace base |
205 } // namespace v8 | 209 } // namespace v8 |
OLD | NEW |