[libc-commits] [libc] [libc][stdlib] Remove LIBC_THREAD_LOCAL from rand_next (PR #96245)
via libc-commits
libc-commits at lists.llvm.org
Thu Jun 20 15:34:00 PDT 2024
https://github.com/PiJoules created https://github.com/llvm/llvm-project/pull/96245
srand and rand do not need to be threadsafe, so it should be permissible to remove thise from rand_next whose only users are srand and rand. This is helpful for the baremetal runtimes where we still need to setup the TLS machinery.
>From 0aef51f5cbf655edb65a728861bb2dc8244dcf5a Mon Sep 17 00:00:00 2001
From: Leonard Chan <leonardchan at google.com>
Date: Thu, 20 Jun 2024 15:31:35 -0700
Subject: [PATCH] [libc][stdlib] Remove LIBC_THREAD_LOCAL from rand_next
srand and rand do not need to be threadsafe, so it should be permissible
to remove thise from rand_next whose only users are srand and rand. This
is helpful for the baremetal runtimes where we still need to setup the
TLS machinery.
---
libc/src/stdlib/rand_util.cpp | 2 +-
libc/src/stdlib/rand_util.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libc/src/stdlib/rand_util.cpp b/libc/src/stdlib/rand_util.cpp
index 1f3dbce9c7860..4aa03bfe3eba9 100644
--- a/libc/src/stdlib/rand_util.cpp
+++ b/libc/src/stdlib/rand_util.cpp
@@ -18,7 +18,7 @@ ThreadLocal<unsigned long> rand_next;
#else
// C standard 7.10p2: If 'rand' is called before 'srand' it is to proceed as if
// the 'srand' function was called with a value of '1'.
-LIBC_THREAD_LOCAL unsigned long rand_next = 1;
+unsigned long rand_next = 1;
#endif
} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdlib/rand_util.h b/libc/src/stdlib/rand_util.h
index cadd6b5cdcbb8..b32302f486dce 100644
--- a/libc/src/stdlib/rand_util.h
+++ b/libc/src/stdlib/rand_util.h
@@ -34,7 +34,7 @@ template <typename T> class ThreadLocal {
extern ThreadLocal<unsigned long> rand_next;
#else
-extern LIBC_THREAD_LOCAL unsigned long rand_next;
+extern unsigned long rand_next;
#endif
} // namespace LIBC_NAMESPACE
More information about the libc-commits
mailing list