1 //===-- Linux implementation of the pthread_mutex_init function -----------===//
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 #include "pthread_mutex_init.h"
10 #include "pthread_mutexattr.h"
12 #include "src/__support/common.h"
13 #include "src/__support/threads/mutex.h"
18 namespace __llvm_libc
{
20 static_assert(sizeof(Mutex
) <= sizeof(pthread_mutex_t
),
21 "The public pthread_mutex_t type cannot accommodate the internal "
24 LLVM_LIBC_FUNCTION(int, pthread_mutex_init
,
26 const pthread_mutexattr_t
*__restrict attr
)) {
27 auto mutexattr
= attr
== nullptr ? DEFAULT_MUTEXATTR
: *attr
;
29 Mutex::init(reinterpret_cast<Mutex
*>(m
), false,
30 get_mutexattr_type(mutexattr
) & PTHREAD_MUTEX_RECURSIVE
,
31 get_mutexattr_robust(mutexattr
) & PTHREAD_MUTEX_ROBUST
);
32 return err
== MutexError::NONE
? 0 : EAGAIN
;
35 } // namespace __llvm_libc