[libc-commits] [libc] [libcxx] [libc][libcxx] Use raw pointer thread handles (PR #195139)
Schrodinger ZHU Yifan via libc-commits
libc-commits at lists.llvm.org
Thu Apr 30 10:53:06 PDT 2026
https://github.com/SchrodingerZhu created https://github.com/llvm/llvm-project/pull/195139
None
>From a4f400ae3fba57046c37488f8c1d7c4c307d34e5 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <yifanzhu at rochester.edu>
Date: Thu, 30 Apr 2026 13:51:10 -0400
Subject: [PATCH] [libc][libcxx] Use raw pointer thread handles
---
libc/include/llvm-libc-types/__thread_type.h | 4 +---
libc/src/pthread/pthread_self.cpp | 3 +--
libc/src/threads/thrd_current.cpp | 3 +--
.../thread.thread.id/format.functions.tests.h | 2 +-
.../thread.thread.class/thread.thread.id/format.pass.cpp | 2 +-
5 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/libc/include/llvm-libc-types/__thread_type.h b/libc/include/llvm-libc-types/__thread_type.h
index 645573f544a99..e2f4829e9fd7f 100644
--- a/libc/include/llvm-libc-types/__thread_type.h
+++ b/libc/include/llvm-libc-types/__thread_type.h
@@ -9,8 +9,6 @@
#ifndef LLVM_LIBC_TYPES___THREAD_TYPE_H
#define LLVM_LIBC_TYPES___THREAD_TYPE_H
-typedef struct {
- void *__attrib;
-} __thread_type;
+typedef void *__thread_type;
#endif // LLVM_LIBC_TYPES___THREAD_TYPE_H
diff --git a/libc/src/pthread/pthread_self.cpp b/libc/src/pthread/pthread_self.cpp
index c3169ec1ca5c4..e810b033170cb 100644
--- a/libc/src/pthread/pthread_self.cpp
+++ b/libc/src/pthread/pthread_self.cpp
@@ -20,8 +20,7 @@ static_assert(sizeof(pthread_t) == sizeof(LIBC_NAMESPACE::Thread),
"Mismatch between pthread_t and internal Thread.");
LLVM_LIBC_FUNCTION(pthread_t, pthread_self, ()) {
- pthread_t th;
- th.__attrib = self.attrib;
+ pthread_t th = self.attrib;
return th;
}
diff --git a/libc/src/threads/thrd_current.cpp b/libc/src/threads/thrd_current.cpp
index 634159712b629..29a0de13ef85e 100644
--- a/libc/src/threads/thrd_current.cpp
+++ b/libc/src/threads/thrd_current.cpp
@@ -19,8 +19,7 @@ static_assert(sizeof(thrd_t) == sizeof(LIBC_NAMESPACE::Thread),
"Mismatch between thrd_t and internal Thread.");
LLVM_LIBC_FUNCTION(thrd_t, thrd_current, ()) {
- thrd_t th;
- th.__attrib = self.attrib;
+ thrd_t th = self.attrib;
return th;
}
diff --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/format.functions.tests.h b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/format.functions.tests.h
index f55f0e2af8cb2..0e97cac28f261 100644
--- a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/format.functions.tests.h
+++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/format.functions.tests.h
@@ -22,7 +22,7 @@ void format_tests(TestFunction check, ExceptionTest check_exception) {
std::thread::id input{};
/***** Test the type specific part *****/
-#if !defined(__APPLE__) && !defined(__FreeBSD__)
+#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__LLVM_LIBC__)
check(SV("0"), SV("{}"), input);
check(SV("0^42"), SV("{}^42"), input);
check(SV("0^42"), SV("{:}^42"), input);
diff --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/format.pass.cpp b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/format.pass.cpp
index 39a257592809d..69156777c2767 100644
--- a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/format.pass.cpp
+++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/format.pass.cpp
@@ -52,7 +52,7 @@ void test_format(StringViewT expected, std::thread::id arg) {
template <class CharT>
void test_fmt() {
-#if !defined(__APPLE__) && !defined(__FreeBSD__)
+#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined (__LLVM_LIBC__)
test_format(SV("0"), std::thread::id());
#else
test_format(SV("0x0"), std::thread::id());
More information about the libc-commits
mailing list