|
9 | 9 | #ifndef LLVM_LIBC_SRC___SUPPORT_THREADS_MUTEX_H |
10 | 10 | #define LLVM_LIBC_SRC___SUPPORT_THREADS_MUTEX_H |
11 | 11 |
|
12 | | -#include "src/__support/macros/properties/architectures.h" |
| 12 | +#include "src/__support/macros/attributes.h" |
| 13 | +#include "src/__support/macros/config.h" |
| 14 | + |
| 15 | +// Uses the platform specific specialization |
| 16 | +#define LIBC_THREAD_MODE_PLATFORM 0 |
| 17 | + |
| 18 | +// Mutex guards nothing, used in single-threaded implementations |
| 19 | +#define LIBC_THREAD_MODE_SINGLE 1 |
| 20 | + |
| 21 | +// Vendor provides implementation |
| 22 | +#define LIBC_THREAD_MODE_EXTERNAL 2 |
| 23 | + |
| 24 | +#if !defined(LIBC_THREAD_MODE) |
| 25 | +#error LIBC_THREAD_MODE is undefined |
| 26 | +#endif // LIBC_THREAD_MODE |
| 27 | + |
| 28 | +#if LIBC_THREAD_MODE != LIBC_THREAD_MODE_PLATFORM && \ |
| 29 | + LIBC_THREAD_MODE != LIBC_THREAD_MODE_SINGLE && \ |
| 30 | + LIBC_THREAD_MODE != LIBC_THREAD_MODE_EXTERNAL |
| 31 | +#error LIBC_THREAD_MODE must be one of the following values: \ |
| 32 | +LIBC_THREAD_MODE_PLATFORM, \ |
| 33 | +LIBC_THREAD_MODE_SINGLE, \ |
| 34 | +LIBC_THREAD_MODE_EXTERNAL. |
| 35 | +#endif |
| 36 | + |
| 37 | +#if LIBC_THREAD_MODE == LIBC_THREAD_MODE_PLATFORM |
13 | 38 |
|
14 | 39 | // Platform independent code will include this header file which pulls |
15 | | -// the platfrom specific specializations using platform macros. |
| 40 | +// the platform specific specializations using platform macros. |
16 | 41 | // |
17 | 42 | // The platform specific specializations should define a class by name |
18 | 43 | // Mutex with non-static methods having the following signature: |
|
39 | 64 |
|
40 | 65 | #if defined(__linux__) |
41 | 66 | #include "src/__support/threads/linux/mutex.h" |
42 | | -#elif defined(LIBC_TARGET_ARCH_IS_GPU) |
43 | | -#include "src/__support/threads/gpu/mutex.h" |
44 | 67 | #endif // __linux__ |
45 | 68 |
|
| 69 | +#elif LIBC_THREAD_MODE == LIBC_THREAD_MODE_SINGLE |
| 70 | + |
| 71 | +#include "src/__support/threads/mutex_common.h" |
| 72 | + |
| 73 | +namespace LIBC_NAMESPACE_DECL { |
| 74 | + |
| 75 | +/// Implementation of a simple passthrough mutex which guards nothing. A |
| 76 | +/// complete Mutex locks in general cannot be implemented on the GPU, or on some |
| 77 | +/// baremetal platforms. We simply define the Mutex interface and require that |
| 78 | +/// only a single thread executes code requiring a mutex lock. |
| 79 | +struct Mutex { |
| 80 | + LIBC_INLINE constexpr Mutex(bool, bool, bool, bool) {} |
| 81 | + |
| 82 | + LIBC_INLINE MutexError lock() { return MutexError::NONE; } |
| 83 | + LIBC_INLINE MutexError unlock() { return MutexError::NONE; } |
| 84 | + LIBC_INLINE MutexError reset() { return MutexError::NONE; } |
| 85 | +}; |
| 86 | + |
| 87 | +} // namespace LIBC_NAMESPACE_DECL |
| 88 | + |
| 89 | +#elif LIBC_THREAD_MODE == LIBC_THREAD_MODE_EXTERNAL |
| 90 | + |
| 91 | +// TODO: Implement the interfacing, if necessary, e.g. "extern struct Mutex;" |
| 92 | + |
| 93 | +#endif // LIBC_THREAD_MODE == LIBC_THREAD_MODE_PLATFORM |
| 94 | + |
46 | 95 | #endif // LLVM_LIBC_SRC___SUPPORT_THREADS_MUTEX_H |
0 commit comments