1*a5ee8183SSiva Chandra Reddy //===-- Linux implementation of the mtx_lock function ---------------------===//
2*a5ee8183SSiva Chandra Reddy //
3*a5ee8183SSiva Chandra Reddy // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*a5ee8183SSiva Chandra Reddy // See https://llvm.org/LICENSE.txt for license information.
5*a5ee8183SSiva Chandra Reddy // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*a5ee8183SSiva Chandra Reddy //
7*a5ee8183SSiva Chandra Reddy //===----------------------------------------------------------------------===//
8*a5ee8183SSiva Chandra Reddy 
9*a5ee8183SSiva Chandra Reddy #include "src/threads/mtx_lock.h"
10*a5ee8183SSiva Chandra Reddy #include "include/threads.h" // For mtx_t definition.
11*a5ee8183SSiva Chandra Reddy #include "src/__support/common.h"
12*a5ee8183SSiva Chandra Reddy #include "src/__support/threads/mutex.h"
13*a5ee8183SSiva Chandra Reddy 
14*a5ee8183SSiva Chandra Reddy namespace __llvm_libc {
15*a5ee8183SSiva Chandra Reddy 
16*a5ee8183SSiva Chandra Reddy // The implementation currently handles only plain mutexes.
17*a5ee8183SSiva Chandra Reddy LLVM_LIBC_FUNCTION(int, mtx_lock, (mtx_t * mutex)) {
18*a5ee8183SSiva Chandra Reddy   auto *m = reinterpret_cast<Mutex *>(mutex);
19*a5ee8183SSiva Chandra Reddy   auto err = m->lock();
20*a5ee8183SSiva Chandra Reddy   return err == MutexError::NONE ? thrd_success : thrd_error;
21*a5ee8183SSiva Chandra Reddy }
22*a5ee8183SSiva Chandra Reddy 
23*a5ee8183SSiva Chandra Reddy } // namespace __llvm_libc
24