[libc-commits] [libc] [libc] inline fast path of callonce (PR #96226)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Thu Jun 20 13:16:59 PDT 2024


================
@@ -9,13 +9,38 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_THREADS_CALLONCE_H
 #define LLVM_LIBC_SRC___SUPPORT_THREADS_CALLONCE_H
 
+#include "src/__support/macros/optimization.h"
+
+#ifdef __linux__
+#include "src/__support/threads/linux/futex_utils.h"
+#else
+#error "callonce is not supported on this platform"
----------------
nickdesaulniers wrote:

This is going to more tightly couple our callonce functionality to linux.  I suspect that will be a problem for GPU/Windows/Darwin.

I think perhaps it's just best to:
1. Have callonce be implemented like:
```c
int callonce (...) {
  if (LIBC_LIKELY(callonce_fastpath())
    return 0;
  return callonce_slowpath();
}
```


1. move the fast path we'd like inlined from libc/src/__support/threads/linux/callonce.cpp to a new header libc/src/__support/threads/linux/callonce.h (add header guards).
3. have libc/src/__support/threads/callonce.h use `ifdef __linux__` to include  libc/src/__support/threads/linux/callonce.h from 1 above.
4. #error otherwise

Then other platforms can get crystal clear build failures and split between inlined fast paths and outlined slow paths (if they even need such a distinction).

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


More information about the libc-commits mailing list