Chromium Code Reviews| Index: native_client_sdk/src/libraries/pthread/pthread.c |
| =================================================================== |
| --- native_client_sdk/src/libraries/pthread/pthread.c (revision 0) |
| +++ native_client_sdk/src/libraries/pthread/pthread.c (revision 0) |
| @@ -0,0 +1,44 @@ |
| +/* Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| +#include <windows.h> |
| +#include <errno.h> |
| +#include "pthread.h" |
| + |
| +int pthread_mutex_init(pthread_mutex_t* m, void* traits) { |
| + *m = (int) CreateMutex(NULL, 0, NULL); |
| + return 0; |
| +} |
| + |
| +int pthread_mutex_destroy(pthread_mutex_t* m) { |
| + CloseHandle((HANDLE) *m); |
| + return 0; |
| +} |
| + |
| +int pthread_mutex_lock(pthread_mutex_t* m) { |
| + if (WaitForSingleObject((HANDLE) *m, INFINITE) == WAIT_OBJECT_0) |
| + return 0; |
| + |
| + return EINVAL; |
| +} |
| + |
| +int pthread_mutex_unlock(pthread_mutex_t* m) { |
| + if (ReleaseMutex((HANDLE) *m)) return 0; |
| + |
| + return EINVAL; |
| +} |
| + |
| +int pthread_mutex_trylock(pthread_mutex_t* m) { |
| + int val = WaitForSingleObject((HANDLE) *m, 0); |
| + |
| + if (val == WAIT_OBJECT_0) return 0; |
| + |
| + if (val == WAIT_TIMEOUT) { |
| + errno = EBUSY; |
| + } |
|
binji
2012/07/23 18:47:14
nit: } else {
or in this case, could just remove t
noelallen1
2012/07/23 21:44:54
Done.
|
| + else { |
| + errno = EINVAL; |
| + } |
| + return -1; |
| +} |
| Property changes on: native_client_sdk\src\libraries\pthread\pthread.c |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |