[libc-commits] [libc] [libc] Implement pthread_getattr_np (PR #221231)
Alexey Samsonov via libc-commits
libc-commits at lists.llvm.org
Fri Sep 4 09:04:51 PDT 2026
================
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of the pthread_getattr_np function (GNU extension).
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/pthread/pthread_getattr_np.h"
+#include "hdr/pthread_macros.h"
+#include "hdr/types/pthread_attr_t.h"
+#include "hdr/types/pthread_t.h"
+#include "src/__support/CPP/atomic.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
+#include "src/__support/threads/thread.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+static_assert(sizeof(pthread_t) == sizeof(LIBC_NAMESPACE::Thread),
+ "Mismatch between pthread_t and internal Thread.");
+
+LLVM_LIBC_FUNCTION(int, pthread_getattr_np,
+ (pthread_t th, pthread_attr_t *attr)) {
+ LIBC_CRASH_ON_NULLPTR(attr);
+ auto *thread = reinterpret_cast<Thread *>(&th);
+
+ uint32_t detach_state =
+ thread->attrib->detach_state.load(cpp::MemoryOrder::RELAXED);
+ attr->__detachstate =
+ (detach_state == static_cast<uint32_t>(DetachState::DETACHED))
----------------
vonosmas wrote:
I looked at the states description, and it looks like `EXITING` should not count as "detached", so the code here seems fine.
https://github.com/llvm/llvm-project/pull/221231
More information about the libc-commits
mailing list