1 //===-- Implementation of the pthread_mutexattr_settype -------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "pthread_mutexattr_settype.h" 10 #include "pthread_mutexattr.h" 11 12 #include "src/__support/common.h" 13 #include "src/__support/macros/config.h" 14 #include "src/errno/libc_errno.h" 15 16 #include <pthread.h> 17 18 namespace LIBC_NAMESPACE_DECL { 19 20 LLVM_LIBC_FUNCTION(int, pthread_mutexattr_settype, 21 (pthread_mutexattr_t *__restrict attr, int type)) { 22 if (type != PTHREAD_MUTEX_NORMAL && type != PTHREAD_MUTEX_ERRORCHECK && 23 type != PTHREAD_MUTEX_RECURSIVE) { 24 return EINVAL; 25 } 26 pthread_mutexattr_t old = *attr; 27 old &= ~unsigned(PThreadMutexAttrPos::TYPE_MASK); 28 *attr = old | (type << unsigned(PThreadMutexAttrPos::TYPE_SHIFT)); 29 return 0; 30 } 31 32 } // namespace LIBC_NAMESPACE_DECL 33