1 : /*
2 : * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can be
4 : * found in the LICENSE file.
5 : */
6 :
7 :
8 : #include <pthread.h>
9 : #include "native_client/src/include/nacl_macros.h"
10 : #include "native_client/src/shared/platform/nacl_sync.h"
11 :
12 1288 : int NaClMutexCtor(struct NaClMutex *mp) {
13 1288 : if (0 != pthread_mutex_init(&mp->mu, (pthread_mutexattr_t *) 0)) {
14 0 : return 0;
15 : }
16 1288 : return 1;
17 : }
18 :
19 870 : void NaClMutexDtor(struct NaClMutex *mp) {
20 870 : pthread_mutex_destroy(&mp->mu);
21 870 : }
22 :
23 435749 : NaClSyncStatus NaClMutexLock(struct NaClMutex *mp) {
24 435749 : pthread_mutex_lock(&mp->mu);
25 435749 : return NACL_SYNC_OK;
26 : }
27 :
28 0 : NaClSyncStatus NaClMutexTryLock(struct NaClMutex *mp) {
29 0 : return (0 == pthread_mutex_trylock(&mp->mu)) ? NACL_SYNC_OK : NACL_SYNC_BUSY;
30 : }
31 :
32 435744 : NaClSyncStatus NaClMutexUnlock(struct NaClMutex *mp) {
33 435744 : pthread_mutex_unlock(&mp->mu);
34 435744 : return NACL_SYNC_OK;
35 : }
|