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 16 matching lines...) Expand all Loading... |
27 USE(result); | 27 USE(result); |
28 } | 28 } |
29 | 29 |
30 | 30 |
31 Semaphore::~Semaphore() { | 31 Semaphore::~Semaphore() { |
32 kern_return_t result = semaphore_destroy(mach_task_self(), native_handle_); | 32 kern_return_t result = semaphore_destroy(mach_task_self(), native_handle_); |
33 DCHECK_EQ(KERN_SUCCESS, result); | 33 DCHECK_EQ(KERN_SUCCESS, result); |
34 USE(result); | 34 USE(result); |
35 } | 35 } |
36 | 36 |
37 void Semaphore::Signal(const char* caller) { | 37 void Semaphore::Signal() { |
38 kern_return_t result = semaphore_signal(native_handle_); | 38 kern_return_t result = semaphore_signal(native_handle_); |
39 DCHECK_EQ(KERN_SUCCESS, result); | 39 DCHECK_EQ(KERN_SUCCESS, result); |
40 USE(result); | 40 USE(result); |
41 USE(caller); | |
42 } | 41 } |
43 | 42 |
44 | 43 |
45 void Semaphore::Wait() { | 44 void Semaphore::Wait() { |
46 while (true) { | 45 while (true) { |
47 kern_return_t result = semaphore_wait(native_handle_); | 46 kern_return_t result = semaphore_wait(native_handle_); |
48 if (result == KERN_SUCCESS) return; // Semaphore was signalled. | 47 if (result == KERN_SUCCESS) return; // Semaphore was signalled. |
49 DCHECK_EQ(KERN_ABORTED, result); | 48 DCHECK_EQ(KERN_ABORTED, result); |
50 } | 49 } |
51 } | 50 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 USE(result); | 96 USE(result); |
98 } | 97 } |
99 | 98 |
100 | 99 |
101 Semaphore::~Semaphore() { | 100 Semaphore::~Semaphore() { |
102 int result = sem_destroy(&native_handle_); | 101 int result = sem_destroy(&native_handle_); |
103 DCHECK_EQ(0, result); | 102 DCHECK_EQ(0, result); |
104 USE(result); | 103 USE(result); |
105 } | 104 } |
106 | 105 |
107 void Semaphore::Signal(const char* caller) { | 106 void Semaphore::Signal() { |
108 int result = sem_post(&native_handle_); | 107 int result = sem_post(&native_handle_); |
109 if (result != 0) { | 108 CHECK_EQ(0, result); |
110 V8_Fatal(__FILE__, __LINE__, | |
111 "Semaphore signal failure: %d called by '%s'\n", errno, caller); | |
112 } | |
113 } | 109 } |
114 | 110 |
115 | 111 |
116 void Semaphore::Wait() { | 112 void Semaphore::Wait() { |
117 while (true) { | 113 while (true) { |
118 int result = sem_wait(&native_handle_); | 114 int result = sem_wait(&native_handle_); |
119 if (result == 0) return; // Semaphore was signalled. | 115 if (result == 0) return; // Semaphore was signalled. |
120 // Signal caused spurious wakeup. | 116 // Signal caused spurious wakeup. |
121 DCHECK_EQ(-1, result); | 117 DCHECK_EQ(-1, result); |
122 DCHECK_EQ(EINTR, errno); | 118 DCHECK_EQ(EINTR, errno); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 DCHECK(native_handle_ != NULL); | 166 DCHECK(native_handle_ != NULL); |
171 } | 167 } |
172 | 168 |
173 | 169 |
174 Semaphore::~Semaphore() { | 170 Semaphore::~Semaphore() { |
175 BOOL result = CloseHandle(native_handle_); | 171 BOOL result = CloseHandle(native_handle_); |
176 DCHECK(result); | 172 DCHECK(result); |
177 USE(result); | 173 USE(result); |
178 } | 174 } |
179 | 175 |
180 void Semaphore::Signal(const char* caller) { | 176 void Semaphore::Signal() { |
181 LONG dummy; | 177 LONG dummy; |
182 BOOL result = ReleaseSemaphore(native_handle_, 1, &dummy); | 178 BOOL result = ReleaseSemaphore(native_handle_, 1, &dummy); |
183 DCHECK(result); | 179 DCHECK(result); |
184 USE(result); | 180 USE(result); |
185 USE(caller); | |
186 } | 181 } |
187 | 182 |
188 | 183 |
189 void Semaphore::Wait() { | 184 void Semaphore::Wait() { |
190 DWORD result = WaitForSingleObject(native_handle_, INFINITE); | 185 DWORD result = WaitForSingleObject(native_handle_, INFINITE); |
191 DCHECK(result == WAIT_OBJECT_0); | 186 DCHECK(result == WAIT_OBJECT_0); |
192 USE(result); | 187 USE(result); |
193 } | 188 } |
194 | 189 |
195 | 190 |
(...skipping 18 matching lines...) Expand all Loading... |
214 DCHECK(result == WAIT_OBJECT_0); | 209 DCHECK(result == WAIT_OBJECT_0); |
215 return true; | 210 return true; |
216 } | 211 } |
217 } | 212 } |
218 } | 213 } |
219 | 214 |
220 #endif // V8_OS_MACOSX | 215 #endif // V8_OS_MACOSX |
221 | 216 |
222 } // namespace base | 217 } // namespace base |
223 } // namespace v8 | 218 } // namespace v8 |
OLD | NEW |