forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc] inline fast path of callonce (llvm#96226)
Split from llvm#91572 --------- Co-authored-by: Nick Desaulniers (paternity leave) <[email protected]>
- Loading branch information
1 parent
2fefc04
commit 6d61d83
Showing
4 changed files
with
58 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//===-- Linux callonce fastpath -------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef LLVM_LIBC_SRC___SUPPORT_THREADS_LINUX_CALLONCE_H | ||
#define LLVM_LIBC_SRC___SUPPORT_THREADS_LINUX_CALLONCE_H | ||
|
||
#include "src/__support/threads/linux/futex_utils.h" | ||
|
||
namespace LIBC_NAMESPACE { | ||
using CallOnceFlag = Futex; | ||
|
||
namespace callonce_impl { | ||
static constexpr FutexWordType NOT_CALLED = 0x0; | ||
static constexpr FutexWordType START = 0x11; | ||
static constexpr FutexWordType WAITING = 0x22; | ||
static constexpr FutexWordType FINISH = 0x33; | ||
|
||
// Avoid cmpxchg operation if the function has already been called. | ||
// The destination operand of cmpxchg may receive a write cycle without | ||
// regard to the result of the comparison. | ||
LIBC_INLINE bool callonce_fastpath(CallOnceFlag *flag) { | ||
return flag->load(cpp::MemoryOrder::RELAXED) == FINISH; | ||
} | ||
} // namespace callonce_impl | ||
|
||
} // namespace LIBC_NAMESPACE | ||
#endif // LLVM_LIBC_SRC___SUPPORT_THREADS_LINUX_CALLONCE_H |