diff options
Diffstat (limited to 'native_client_sdk/src/libraries/pthread/pthread.c')
-rw-r--r-- | native_client_sdk/src/libraries/pthread/pthread.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/native_client_sdk/src/libraries/pthread/pthread.c b/native_client_sdk/src/libraries/pthread/pthread.c new file mode 100644 index 0000000..68f4fc2 --- /dev/null +++ b/native_client_sdk/src/libraries/pthread/pthread.c @@ -0,0 +1,43 @@ +/* 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; + } else { + errno = EINVAL; + } + return -1; +}
\ No newline at end of file |