1a5ee8183SSiva Chandra Reddy //===-- Linux implementation of the mtx_init function ---------------------===// 2a5ee8183SSiva Chandra Reddy // 3a5ee8183SSiva Chandra Reddy // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4a5ee8183SSiva Chandra Reddy // See https://llvm.org/LICENSE.txt for license information. 5a5ee8183SSiva Chandra Reddy // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6a5ee8183SSiva Chandra Reddy // 7a5ee8183SSiva Chandra Reddy //===----------------------------------------------------------------------===// 8a5ee8183SSiva Chandra Reddy 9a5ee8183SSiva Chandra Reddy #include "src/threads/mtx_init.h" 10a5ee8183SSiva Chandra Reddy #include "src/__support/common.h" 11*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h" 12a5ee8183SSiva Chandra Reddy #include "src/__support/threads/mutex.h" 13a5ee8183SSiva Chandra Reddy 148910cc27SPetr Hosek #include <threads.h> // For mtx_t definition. 158910cc27SPetr Hosek 16*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL { 17a5ee8183SSiva Chandra Reddy 182e7cb8c7SSiva Chandra Reddy static_assert(sizeof(Mutex) <= sizeof(mtx_t), 192e7cb8c7SSiva Chandra Reddy "The public mtx_t type cannot accommodate the internal mutex " 202e7cb8c7SSiva Chandra Reddy "type."); 212e7cb8c7SSiva Chandra Reddy 22a5ee8183SSiva Chandra Reddy LLVM_LIBC_FUNCTION(int, mtx_init, (mtx_t * m, int type)) { 232e7cb8c7SSiva Chandra Reddy auto err = Mutex::init(reinterpret_cast<Mutex *>(m), type & mtx_timed, 24142afde0SSchrodinger ZHU Yifan type & mtx_recursive, /* is_robust */ false, 25142afde0SSchrodinger ZHU Yifan /* is_pshared */ false); 26a5ee8183SSiva Chandra Reddy return err == MutexError::NONE ? thrd_success : thrd_error; 27a5ee8183SSiva Chandra Reddy } 28a5ee8183SSiva Chandra Reddy 29*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL 30