OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. |
| 4 */ |
| 5 #include <windows.h> |
| 6 #include <errno.h> |
| 7 #include "pthread.h" |
| 8 |
| 9 int pthread_mutex_init(pthread_mutex_t* m, void* traits) { |
| 10 *m = (int) CreateMutex(NULL, 0, NULL); |
| 11 return 0; |
| 12 } |
| 13 |
| 14 int pthread_mutex_destroy(pthread_mutex_t* m) { |
| 15 CloseHandle((HANDLE) *m); |
| 16 return 0; |
| 17 } |
| 18 |
| 19 int pthread_mutex_lock(pthread_mutex_t* m) { |
| 20 if (WaitForSingleObject((HANDLE) *m, INFINITE) == WAIT_OBJECT_0) |
| 21 return 0; |
| 22 |
| 23 return EINVAL; |
| 24 } |
| 25 |
| 26 int pthread_mutex_unlock(pthread_mutex_t* m) { |
| 27 if (ReleaseMutex((HANDLE) *m)) return 0; |
| 28 |
| 29 return EINVAL; |
| 30 } |
| 31 |
| 32 int pthread_mutex_trylock(pthread_mutex_t* m) { |
| 33 int val = WaitForSingleObject((HANDLE) *m, 0); |
| 34 |
| 35 if (val == WAIT_OBJECT_0) return 0; |
| 36 |
| 37 if (val == WAIT_TIMEOUT) { |
| 38 errno = EBUSY; |
| 39 } else { |
| 40 errno = EINVAL; |
| 41 } |
| 42 return -1; |
| 43 } |
OLD | NEW |