File tree Expand file tree Collapse file tree 2 files changed +6
-13
lines changed
libc/src/__support/threads Expand file tree Collapse file tree 2 files changed +6
-13
lines changed Original file line number Diff line number Diff line change 2323#endif
2424
2525namespace LIBC_NAMESPACE_DECL {
26-
27- // Common definitions
28- namespace callonce_impl {
29- template <class CallOnceCallback >
30- [[gnu::noinline]] int callonce_slowpath (CallOnceFlag *flag,
31- CallOnceCallback callback);
32- } // namespace callonce_impl
33-
3426template <class CallOnceCallback >
3527LIBC_INLINE int callonce (CallOnceFlag *flag, CallOnceCallback callback) {
3628 if (LIBC_LIKELY (callonce_impl::callonce_fastpath (flag)))
3729 return 0 ;
3830
39- return callonce_impl::callonce_slowpath (flag, callback);
31+ return callonce_impl::callonce_slowpath (flag, &callback, [](void *arg) {
32+ (*static_cast <CallOnceCallback *>(arg))();
33+ });
4034}
4135} // namespace LIBC_NAMESPACE_DECL
4236
Original file line number Diff line number Diff line change @@ -27,9 +27,8 @@ LIBC_INLINE bool callonce_fastpath(CallOnceFlag *flag) {
2727 return flag->load (cpp::MemoryOrder::RELAXED) == FINISH;
2828}
2929
30- template <class CallOnceCallback >
31- [[gnu::noinline]] int callonce_slowpath (CallOnceFlag *flag,
32- CallOnceCallback callback) {
30+ [[gnu::cold, gnu::noinline]] LIBC_INLINE int
31+ callonce_slowpath (CallOnceFlag *flag, void *payload, void (*callback)(void *)) {
3332
3433 auto *futex_word = reinterpret_cast <Futex *>(flag);
3534
@@ -38,7 +37,7 @@ template <class CallOnceCallback>
3837 // The call_once call can return only after the called function |func|
3938 // returns. So, we use futexes to synchronize calls with the same flag value.
4039 if (futex_word->compare_exchange_strong (not_called, START)) {
41- callback ();
40+ callback (payload );
4241 auto status = futex_word->exchange (FINISH);
4342 if (status == WAITING)
4443 futex_word->notify_all ();
You can’t perform that action at this time.
0 commit comments