[libc-commits] [libc] [libc] Mutex implementation for single-threaded baremetal (PR #145358)

Petr Hosek via libc-commits libc-commits at lists.llvm.org
Tue Jun 24 00:33:03 PDT 2025


petrhosek wrote:

The main concern I have with this change is that it furthers the notion of baremetal as a singular platform whereas in practice there is a diverse set of baremetal platforms. For that reason, I'm starting to consider the existence of `baremetal` implementation subdirectories in LLVM libc to be an antipattern and I think we should aim to eliminate these directories and baremetal should be just a build configuration.

Rather than introducing `threads/baremetal/mutex.h`, I think we should introduce a threading mode configuration option akin to what we've done for [errno](https://github.com/llvm/llvm-project/blob/0f173a0f9af54a3117657135cd23e079c3c626ad/libc/src/__support/libc_errno.h). That is, we would introduce `LIBC_CONF_THREAD_MODE` with values such as:

* `LIBC_THREAD_MODE_SINGLE`: this would be the implementation in this PR,
* `LIBC_THREAD_MODE_EXTERNAL`: we could make it a no-op or `#error` for now,
* `LIBC_THREAD_MODE_PLATFORM`: this would be the platform specific implementation for platforms such as Linux.

For baremetal build configuration we would default to `LIBC_THREAD_MODE_SINGLE`.

I don't expect this to be significantly more complicated than the current PR, but it would more flexible and there might be other build configurations beyond baremetal where `LIBC_THREAD_MODE_SINGLE` might be useful.

https://github.com/llvm/llvm-project/pull/145358


More information about the libc-commits mailing list