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 
14 #include <errno.h>
15 #include <pthread.h>
16 
17 namespace __llvm_libc {
18 
19 LLVM_LIBC_FUNCTION(int, pthread_mutexattr_settype,
20                    (pthread_mutexattr_t *__restrict attr, int type)) {
21   if (type != PTHREAD_MUTEX_NORMAL && type != PTHREAD_MUTEX_ERRORCHECK &&
22       type != PTHREAD_MUTEX_RECURSIVE) {
23     return EINVAL;
24   }
25   pthread_mutexattr_t old = *attr;
26   old &= ~unsigned(PThreadMutexAttrPos::TYPE_MASK);
27   *attr = old | (type << unsigned(PThreadMutexAttrPos::TYPE_SHIFT));
28   return 0;
29 }
30 
31 } // namespace __llvm_libc
32