[NFC][Py Reformat] Added more commits to .git-blame-ignore-revs
[llvm-project.git] / libc / src / pthread / pthread_mutex_init.cpp
blob5038ee08875939be5bd0177e25e13f90bc280d85
1 //===-- Linux implementation of the pthread_mutex_init function -----------===//
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 //===----------------------------------------------------------------------===//
9 #include "pthread_mutex_init.h"
10 #include "pthread_mutexattr.h"
12 #include "src/__support/common.h"
13 #include "src/__support/threads/mutex.h"
15 #include <errno.h>
16 #include <pthread.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 "
22 "mutex type.");
24 LLVM_LIBC_FUNCTION(int, pthread_mutex_init,
25 (pthread_mutex_t * m,
26 const pthread_mutexattr_t *__restrict attr)) {
27 auto mutexattr = attr == nullptr ? DEFAULT_MUTEXATTR : *attr;
28 auto err =
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