[libc-commits] [libc] [libc] Mutex implementation for single-threaded baremetal (PR #145358)
Petr Hosek via libc-commits
libc-commits at lists.llvm.org
Thu Jul 31 01:23:47 PDT 2025
petrhosek wrote:
> Do you think it would be better to share the configuration of `LIBC_THREAD_MODE` with `LIBC_ERRNO_MODE`?
>
> 1. LIBC_ERRNO_MODE_SHARED (single thread), LIBC_ERRNO_MODE_SYSTEM (platform) and LIBC_ERRNO_MODE_EXTERNAL (external) already exist.
> 2. Ideally I want the `LIBC_THREAD_LOCAL` to be controlled by this build variable. Unfortunately `libcxx` includes headers directly through `shared/*` but then we can just define it in `errno.h` and include that in `shared/libc_common.h` like so: `#include <errno.h>`
> 3. I can't think of another mode to `LIBC_THREAD_MODE` that isn't compatible with `LIBC_ERRNO_MODE`, so we can just stick with `LIBC_ERRNO_MODE` (which deduces the Mutex type).
>
> If you're happy with that I can redo this PR in one go.
I'd keep them separate since they're technically orthogonal and I think we should avoid overloading the meaning of `LIBC_ERRNO_MODE`. LLVM libc is meant to be usable "a la carte" and we want to give users flexibility to configure the implementation as they fit.
I expect we'll redo the `Mutex` interface in the future since the current design is quite limited and at that point we may revisit `LIBC_THREAD_MODE` and potentially remove/replace it, but I'm happy with this change as an incremental step.
https://github.com/llvm/llvm-project/pull/145358
More information about the libc-commits
mailing list