1 //===-- Linux implementation of the pthread_setname_np function -----------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "pthread_getname_np.h"
11 #include "src/__support/CPP/span.h"
12 #include "src/__support/CPP/stringstream.h"
13 #include "src/__support/common.h"
14 #include "src/__support/threads/thread.h"
19 namespace __llvm_libc
{
21 static_assert(sizeof(pthread_t
) == sizeof(__llvm_libc::Thread
),
22 "Mismatch between pthread_t and internal Thread.");
24 LLVM_LIBC_FUNCTION(int, pthread_getname_np
,
25 (pthread_t th
, char *buf
, size_t len
)) {
26 auto *thread
= reinterpret_cast<__llvm_libc::Thread
*>(&th
);
27 cpp::span
<char> name_buf(buf
, len
);
28 cpp::StringStream
name_stream(name_buf
);
29 return thread
->get_name(name_stream
);
32 } // namespace __llvm_libc