[PATCH] D131313: [Support] Use constexpr if
Jun Zhang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 6 02:56:18 PDT 2022
junaire updated this revision to Diff 450504.
junaire added a comment.
Clang-format
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D131313/new/
https://reviews.llvm.org/D131313
Files:
llvm/include/llvm/Support/Mutex.h
llvm/include/llvm/Support/Threading.h
llvm/lib/Support/Threading.cpp
Index: llvm/lib/Support/Threading.cpp
===================================================================
--- llvm/lib/Support/Threading.cpp
+++ llvm/lib/Support/Threading.cpp
@@ -28,14 +28,6 @@
//=== independent code.
//===----------------------------------------------------------------------===//
-bool llvm::llvm_is_multithreaded() {
-#if LLVM_ENABLE_THREADS != 0
- return true;
-#else
- return false;
-#endif
-}
-
#if LLVM_ENABLE_THREADS == 0 || \
(!defined(_WIN32) && !defined(HAVE_PTHREAD_H))
uint64_t llvm::get_threadid() { return 0; }
Index: llvm/include/llvm/Support/Threading.h
===================================================================
--- llvm/include/llvm/Support/Threading.h
+++ llvm/include/llvm/Support/Threading.h
@@ -50,7 +50,11 @@
/// Returns true if LLVM is compiled with support for multi-threading, and
/// false otherwise.
-bool llvm_is_multithreaded();
+constexpr bool llvm_is_multithreaded() {
+ if constexpr (LLVM_ENABLE_THREADS)
+ return true;
+ return false;
+}
#if LLVM_THREADING_USE_STD_CALL_ONCE
Index: llvm/include/llvm/Support/Mutex.h
===================================================================
--- llvm/include/llvm/Support/Mutex.h
+++ llvm/include/llvm/Support/Mutex.h
@@ -31,36 +31,34 @@
public:
bool lock() {
- if (!mt_only || llvm_is_multithreaded()) {
+ if constexpr (!mt_only || llvm_is_multithreaded()) {
impl.lock();
return true;
- } else {
+ }
// Single-threaded debugging code. This would be racy in
// multithreaded mode, but provides not basic checks in single
// threaded mode.
++acquired;
return true;
- }
}
bool unlock() {
- if (!mt_only || llvm_is_multithreaded()) {
+ if constexpr (!mt_only || llvm_is_multithreaded()) {
impl.unlock();
return true;
- } else {
+ }
// Single-threaded debugging code. This would be racy in
// multithreaded mode, but provides not basic checks in single
// threaded mode.
assert(acquired && "Lock not acquired before release!");
--acquired;
return true;
- }
}
bool try_lock() {
- if (!mt_only || llvm_is_multithreaded())
+ if constexpr (!mt_only || llvm_is_multithreaded())
return impl.try_lock();
- else return true;
+ return true;
}
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131313.450504.patch
Type: text/x-patch
Size: 2556 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220806/34d41a02/attachment.bin>
More information about the llvm-commits
mailing list