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