brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 8df3ae2 Raw
34 lines · cpp
1//===-- Linux implementation of the pthread_setname_np function -----------===//2//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "pthread_getname_np.h"10 11#include "src/__support/CPP/span.h"12#include "src/__support/CPP/stringstream.h"13#include "src/__support/common.h"14#include "src/__support/macros/config.h"15#include "src/__support/threads/thread.h"16 17#include <pthread.h>18#include <stddef.h>19 20namespace LIBC_NAMESPACE_DECL {21 22static_assert(sizeof(pthread_t) == sizeof(LIBC_NAMESPACE::Thread),23              "Mismatch between pthread_t and internal Thread.");24 25LLVM_LIBC_FUNCTION(int, pthread_getname_np,26                   (pthread_t th, char *buf, size_t len)) {27  auto *thread = reinterpret_cast<LIBC_NAMESPACE::Thread *>(&th);28  cpp::span<char> name_buf(buf, len);29  cpp::StringStream name_stream(name_buf);30  return thread->get_name(name_stream);31}32 33} // namespace LIBC_NAMESPACE_DECL34