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 "include/threads.h" // For mtx_t definition.
11a5ee8183SSiva Chandra Reddy #include "src/__support/common.h"
12a5ee8183SSiva Chandra Reddy #include "src/__support/threads/mutex.h"
13a5ee8183SSiva Chandra Reddy 
14a5ee8183SSiva Chandra Reddy namespace __llvm_libc {
15a5ee8183SSiva Chandra Reddy 
16*2e7cb8c7SSiva Chandra Reddy static_assert(sizeof(Mutex) <= sizeof(mtx_t),
17*2e7cb8c7SSiva Chandra Reddy               "The public mtx_t type cannot accommodate the internal mutex "
18*2e7cb8c7SSiva Chandra Reddy               "type.");
19*2e7cb8c7SSiva Chandra Reddy 
20a5ee8183SSiva Chandra Reddy LLVM_LIBC_FUNCTION(int, mtx_init, (mtx_t * m, int type)) {
21*2e7cb8c7SSiva Chandra Reddy   auto err = Mutex::init(reinterpret_cast<Mutex *>(m), type & mtx_timed,
22*2e7cb8c7SSiva Chandra Reddy                          type & mtx_recursive, 0);
23a5ee8183SSiva Chandra Reddy   return err == MutexError::NONE ? thrd_success : thrd_error;
24a5ee8183SSiva Chandra Reddy }
25a5ee8183SSiva Chandra Reddy 
26a5ee8183SSiva Chandra Reddy } // namespace __llvm_libc
27