Skip to content

Commit d47e596

Browse files
committed
[libc] Mutex implementation for single-threaded baremetal
1 parent 5a16645 commit d47e596

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
add_header_library(
2+
mutex
3+
HDRS
4+
mutex.h
5+
)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//===--- Implementation of a mutex class for baremetal ----------*- C++ -*-===//
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+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC___SUPPORT_THREADS_BAREMETAL_MUTEX_H
10+
#define LLVM_LIBC_SRC___SUPPORT_THREADS_BAREMETAL_MUTEX_H
11+
12+
#include "src/__support/macros/attributes.h"
13+
#include "src/__support/macros/config.h"
14+
#include "src/__support/threads/mutex_common.h"
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
/// Implementation of a simple passthrough mutex which guards nothing. For
19+
/// single threaded processors, this is the implementation.
20+
struct Mutex {
21+
LIBC_INLINE constexpr Mutex(bool, bool, bool, bool) {}
22+
23+
LIBC_INLINE MutexError lock() { return MutexError::NONE; }
24+
LIBC_INLINE MutexError unlock() { return MutexError::NONE; }
25+
LIBC_INLINE MutexError reset() { return MutexError::NONE; }
26+
};
27+
28+
// TODO: add multithreading support here
29+
30+
} // namespace LIBC_NAMESPACE_DECL
31+
32+
#endif // LLVM_LIBC_SRC___SUPPORT_THREADS_BAREMETAL_MUTEX_H

libc/src/__support/threads/mutex.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include "src/__support/threads/linux/mutex.h"
4242
#elif defined(LIBC_TARGET_ARCH_IS_GPU)
4343
#include "src/__support/threads/gpu/mutex.h"
44+
#elif defined(__ELF__)
45+
#include "src/__support/threads/baremetal/mutex.h"
4446
#endif // __linux__
4547

4648
#endif // LLVM_LIBC_SRC___SUPPORT_THREADS_MUTEX_H

0 commit comments

Comments
 (0)