1 /* 2 * Copyright (c) 2012 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 #include "native_client/src/shared/platform/nacl_check.h" 8 #include "native_client/src/shared/platform/nacl_host_desc.h" 9 #include "native_client/src/shared/platform/posix/nacl_fast_mutex.h" 10 NaClFastMutexCtor(struct NaClFastMutex * flp)11int NaClFastMutexCtor(struct NaClFastMutex *flp) { 12 if (0 != pthread_mutex_init(&flp->mu, (pthread_mutexattr_t *) NULL)) { 13 return 0; 14 } 15 return 1; 16 } 17 NaClFastMutexDtor(struct NaClFastMutex * flp)18void NaClFastMutexDtor(struct NaClFastMutex *flp) { 19 pthread_mutex_destroy(&flp->mu); 20 } 21 NaClFastMutexLock(struct NaClFastMutex * flp)22void NaClFastMutexLock(struct NaClFastMutex *flp) { 23 CHECK(0 == pthread_mutex_lock(&flp->mu)); 24 } 25 NaClFastMutexTryLock(struct NaClFastMutex * flp)26int NaClFastMutexTryLock(struct NaClFastMutex *flp) { 27 return NaClXlateErrno(pthread_mutex_trylock(&flp->mu)); 28 } 29 NaClFastMutexUnlock(struct NaClFastMutex * flp)30void NaClFastMutexUnlock(struct NaClFastMutex *flp) { 31 CHECK(0 == pthread_mutex_unlock(&flp->mu)); 32 } 33