Skip to content

Commit ddcb3d6

Browse files
more cleanup
1 parent 22cdfea commit ddcb3d6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

libc/src/__support/threads/linux/callonce.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)