1 //===-- Declarations related mutex attribute objects -----------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC_PTHREAD_PTHREAD_MUTEXATTR_H
10 #define LLVM_LIBC_SRC_PTHREAD_PTHREAD_MUTEXATTR_H
12 #include "src/__support/common.h"
16 namespace __llvm_libc
{
18 enum class PThreadMutexAttrPos
: unsigned int {
20 TYPE_MASK
= 0x3 << TYPE_SHIFT
, // Type is encoded in 2 bits
23 ROBUST_MASK
= 0x1 << ROBUST_SHIFT
,
26 PSHARED_MASK
= 0x1 << PSHARED_SHIFT
,
28 // TODO: Add a mask for protocol and prioceiling when it is supported.
31 constexpr pthread_mutexattr_t DEFAULT_MUTEXATTR
=
32 PTHREAD_MUTEX_DEFAULT
<< unsigned(PThreadMutexAttrPos::TYPE_SHIFT
) |
33 PTHREAD_MUTEX_STALLED
<< unsigned(PThreadMutexAttrPos::ROBUST_SHIFT
) |
34 PTHREAD_PROCESS_PRIVATE
<< unsigned(PThreadMutexAttrPos::PSHARED_SHIFT
);
36 LIBC_INLINE
int get_mutexattr_type(pthread_mutexattr_t attr
) {
37 return (attr
& unsigned(PThreadMutexAttrPos::TYPE_MASK
)) >>
38 unsigned(PThreadMutexAttrPos::TYPE_SHIFT
);
41 LIBC_INLINE
int get_mutexattr_robust(pthread_mutexattr_t attr
) {
42 return (attr
& unsigned(PThreadMutexAttrPos::ROBUST_MASK
)) >>
43 unsigned(PThreadMutexAttrPos::ROBUST_SHIFT
);
46 } // namespace __llvm_libc
48 #endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_MUTEXATTR_H