55 lines · c
1//===-- Declarations related mutex attribute objects -----------*- C++ -*-===//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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_SRC_PTHREAD_PTHREAD_MUTEXATTR_H10#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_MUTEXATTR_H11 12#include "src/__support/common.h"13#include "src/__support/macros/config.h"14 15#include <pthread.h>16 17namespace LIBC_NAMESPACE_DECL {18 19enum class PThreadMutexAttrPos : unsigned int {20 TYPE_SHIFT = 0,21 TYPE_MASK = 0x3 << TYPE_SHIFT, // Type is encoded in 2 bits22 23 ROBUST_SHIFT = 2,24 ROBUST_MASK = 0x1 << ROBUST_SHIFT,25 26 PSHARED_SHIFT = 3,27 PSHARED_MASK = 0x1 << PSHARED_SHIFT,28 29 // TODO: Add a mask for protocol and prioceiling when it is supported.30};31 32constexpr pthread_mutexattr_t DEFAULT_MUTEXATTR =33 PTHREAD_MUTEX_DEFAULT << unsigned(PThreadMutexAttrPos::TYPE_SHIFT) |34 PTHREAD_MUTEX_STALLED << unsigned(PThreadMutexAttrPos::ROBUST_SHIFT) |35 PTHREAD_PROCESS_PRIVATE << unsigned(PThreadMutexAttrPos::PSHARED_SHIFT);36 37LIBC_INLINE int get_mutexattr_type(pthread_mutexattr_t attr) {38 return (attr & unsigned(PThreadMutexAttrPos::TYPE_MASK)) >>39 unsigned(PThreadMutexAttrPos::TYPE_SHIFT);40}41 42LIBC_INLINE int get_mutexattr_robust(pthread_mutexattr_t attr) {43 return (attr & unsigned(PThreadMutexAttrPos::ROBUST_MASK)) >>44 unsigned(PThreadMutexAttrPos::ROBUST_SHIFT);45}46 47LIBC_INLINE int get_mutexattr_pshared(pthread_mutexattr_t attr) {48 return (attr & unsigned(PThreadMutexAttrPos::PSHARED_MASK)) >>49 unsigned(PThreadMutexAttrPos::PSHARED_SHIFT);50}51 52} // namespace LIBC_NAMESPACE_DECL53 54#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_MUTEXATTR_H55