[Driver][FreeBSD] Remove FreeBSD/loongarch32 support (#122515)
[llvm-project.git] / libc / src / __support / threads / identifier.h
bloba570abfd5dc73cefea59a92000ed764412cdf547
1 //===--- Thread Identifier Header --------------------------------*- C++-*-===//
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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC___SUPPORT_THREADS_IDENTIFIER_H
10 #define LLVM_LIBC_SRC___SUPPORT_THREADS_IDENTIFIER_H
12 #ifdef LIBC_FULL_BUILD
13 #include "src/__support/threads/thread.h"
14 #endif // LIBC_FULL_BUILD
16 #include "hdr/types/pid_t.h"
17 #include "src/__support/OSUtil/syscall.h"
18 #include "src/__support/macros/optimization.h"
19 #include <sys/syscall.h>
21 namespace LIBC_NAMESPACE_DECL {
22 namespace internal {
24 LIBC_INLINE pid_t *get_tid_cache() {
25 #ifdef LIBC_FULL_BUILD
26 return &self.attrib->tid;
27 #else
28 // in non-full build mode, we do not control the fork routine. Therefore,
29 // we do not cache tid at all.
30 return nullptr;
31 #endif
34 LIBC_INLINE pid_t gettid() {
35 pid_t *cache = get_tid_cache();
36 if (LIBC_UNLIKELY(!cache || *cache <= 0))
37 return syscall_impl<pid_t>(SYS_gettid);
38 return *cache;
41 LIBC_INLINE void force_set_tid(pid_t tid) {
42 pid_t *cache = get_tid_cache();
43 if (cache)
44 *cache = tid;
47 } // namespace internal
48 } // namespace LIBC_NAMESPACE_DECL
50 #endif // LLVM_LIBC_SRC___SUPPORT_THREADS_IDENTIFIER_H