File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed
libc/src/__support/threads/linux Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -27,27 +27,27 @@ LIBC_INLINE bool callonce_fastpath(CallOnceFlag *flag) {
2727 return flag->load (cpp::MemoryOrder::RELAXED) == FINISH;
2828}
2929
30- [[gnu::noinline]]
31- LIBC_INLINE int callonce_slowpath (CallOnceFlag *flag, void (*func)(void )) {
30+ template <class CallOnceCallback >
31+ [[gnu::noinline]] int callonce_slowpath (CallOnceFlag *flag,
32+ CallOnceCallback callback) {
33+
3234 auto *futex_word = reinterpret_cast <Futex *>(flag);
3335
3436 FutexWordType not_called = NOT_CALLED;
3537
3638 // The call_once call can return only after the called function |func|
3739 // returns. So, we use futexes to synchronize calls with the same flag value.
3840 if (futex_word->compare_exchange_strong (not_called, START)) {
39- func ();
41+ callback ();
4042 auto status = futex_word->exchange (FINISH);
4143 if (status == WAITING)
4244 futex_word->notify_all ();
4345 return 0 ;
4446 }
4547
4648 FutexWordType status = START;
47- if (futex_word->compare_exchange_strong (status, WAITING) ||
48- status == WAITING) {
49+ if (futex_word->compare_exchange_strong (status, WAITING) || status == WAITING)
4950 futex_word->wait (WAITING);
50- }
5151
5252 return 0 ;
5353}
You can’t perform that action at this time.
0 commit comments