summaryrefslogtreecommitdiff
path: root/libc/src/__support/threads/thread.h
AgeCommit message (Collapse)Author
2025-09-03[libc] ensure tls dtors are called in main thread (#133641)Schrodinger ZHU Yifan
This is a part of allocator patch since I want to make sure the TLS for allocators are correctly handled. TLS dtors are not invoked on exit previously. This departures from major libc implementations. This PR fixes the issue by aligning the behavior with bionic. https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/bionic/exit.cpp I believe the finalization order is also consistent with glibc now: On main thread exiting: - pthread_key dtors are not called (unless exiting with `pthread_exit`) - `__cxa` based tls dtors are called - `::__cxa_atexit` and `::atexit` dtors are called - `.fini` dtors are called ![image](https://github.com/user-attachments/assets/737c4845-cab6-47a9-aa00-32997be141bd)
2025-07-23[libc][NFC] Add stdint.h proxy header to fix dependency issue with ↵lntue
<stdint.h> includes. (#150303) https://github.com/llvm/llvm-project/issues/149993
2024-08-02[libc] inline thread self (#101739)Schrodinger ZHU Yifan
The codegen for non-inlined version is "quite ugly" as it emits some checks to make sure the initialization routine is properly executed because the compiler does not see how the TLS object is initialized. This leads to some `callq 0x0` junk in the final outputs. For codegen details, see https://godbolt.org/z/rb5qYj3vY.
2024-07-27revert all tid changes (#100915)Schrodinger ZHU Yifan
2024-07-22[libc][NFC] clean up some includes (#99719)Michael Jones
While looking through the list of includes for #99693 I found these includes that also need to be cleaned up. I removed the extra includes in expm1.cpp, but the include in thread.h needs more attention so I just marked it with a todo.
2024-07-20[libc] Added static casts to fix implicit conversion warnings in 32-bit systemsMikhail R. Gadelha
This patch fixes: randomness.h and getauxval.cpp were passing ssize_t as size_t kernel_statx.h was assigning an uint64_t to uintptr_t fopencookie.cpp was trying to create a FileIOResult using ssize_t but the constructor expected a size_t thread.h was trying to call free_stack (which takes a size_t) with an unsigned long long. free_stack does the calculations using uintptr_t, so I changed the passing values to size_t
2024-07-20reland "[libc] implement cached process/thread identity (#98989)" (#99765)Schrodinger ZHU Yifan
2024-07-18Revert "[libc] implement cached process/thread identity" (#99559)Schrodinger ZHU Yifan
Reverts llvm/llvm-project#98989
2024-07-18[libc] implement cached process/thread identity (#98989)Schrodinger ZHU Yifan
migrated from https://github.com/llvm/llvm-project/pull/95965 due to corrupted git history
2024-07-12[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98597)Petr Hosek
This is a part of #97655.
2024-07-12Revert "[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace ↵Mehdi Amini
declaration" (#98593) Reverts llvm/llvm-project#98075 bots are broken
2024-07-11[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98075)Petr Hosek
This is a part of #97655.
2024-06-25[libc][arm32] define argc type and stack alignment (#96367)Nick Desaulniers (paternity leave)
https://github.com/ARM-software/abi-aa/blob/main/aapcs32/aapcs32.rst#6212stack-constraints-at-a-public-interface mentions that the stack on ARM32 is double word aligned. Remove confused comments around ArgcType. argc is always an int, passed on the stack, so we need to store a pointer to it (regardless of ILP32 or LP64).
2023-09-26[libc] Start to refactor riscv platform abstraction to support both 32 and ↵Mikhail R. Gadelha
64 bits versions This patch enables the compilation of libc for rv32 by unifying the current rv64 and rv32 implementation into a single rv implementation. We updated the cmake file to match the new riscv32 arch and force LIBC_TARGET_ARCHITECTURE to be "riscv" whenever we find "riscv32" or "riscv64". This is required as LIBC_TARGET_ARCHITECTURE is used in the path for several platform specific implementations. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D148797
2023-09-26[libc] Mass replace enclosing namespace (#67032)Guillaume Chatelet
This is step 4 of https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079
2023-09-21[libc][clang-tidy] Add llvm-header-guard to get consistant naming and ↵Guillaume Chatelet
prevent file copy/paste issues. (#66477)
2023-05-25[libc] Add macro LIBC_THREAD_LOCAL.Siva Chandra Reddy
It resolves to thread_local on all platform except for the GPUs on which it resolves to nothing. The use of thread_local in the source code has been replaced with the new macro. Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D151486
2023-05-22Cleanup code in `thread_exit`Noah Goldstein
1) Avoid proper function calls and referencing local variables after the stack has been deallocated. A proper function call/return or local variable reference that may have spilled will cause invalid memory reads after the stack has been deallocated. 2) Mark the function as [[noreturn]] and place `__builtin_unreachable()` after the `SYS_exit` syscalls. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D151142
2023-05-22Support custom attributes in pthread_createNoah Goldstein
Only functional for stack growsdown (same as before), but custom `stack`, `stacksize`, `guardsize`, and `detachstate` all should be working. Differential Revision: https://reviews.llvm.org/D148290
2023-04-20[LIBC] Fix incorrect handling of `pthread_join(tid, nullptr)`Noah Goldstein
Previously unconditionally stored to the return value. This is incorrect, we should only return if user value is non-null. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D148293
2023-03-09[libc] Extend the linux thread implementation for riscv64.Siva Chandra
Also, added riscv64 startup code for static linking which is used by the integration tests. Functions from the C standard threads library have been enabled. Reviewed By: mikhail.ramalho Differential Revision: https://reviews.llvm.org/D145670
2023-02-09[libc][NFC] Move architectures.h to properties subfolderGuillaume Chatelet
2023-02-07[libc][NFC] Rename macrosGuillaume Chatelet
2023-02-07[libc][NFC] Rename architecture macros and move to macros folderGuillaume Chatelet
2022-08-22[libc][NFC] Use STL case for string_viewGuillaume Chatelet
2022-08-12[libc] Add implemementations of thread specific data related API.Siva Chandra Reddy
Specifically, POSIX functions pthread_key_create, pthread_key_delete, pthread_setspecific and pthread_getspecific have been added. The C standard equivalents tss_create, tss_delete, tss_set and tss_get have also been added. Reviewed By: lntue, michaelrj Differential Revision: https://reviews.llvm.org/D131647
2022-08-10[libc] Add implementation of pthread_exit and thrd_exit.Siva Chandra Reddy
Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D131451
2022-08-02[libc] Add GNU extension functions pthread_setname_np and pthread_getname_np.Siva Chandra Reddy
Reviewed By: michaelrj, lntue Differential Revision: https://reviews.llvm.org/D130872
2022-07-14[libc] Add implementations of pthread_equal and pthread_self.Siva Chandra Reddy
Reviewed By: michaelrj, lntue Differential Revision: https://reviews.llvm.org/D129729
2022-07-13[libc] Linux threads - Setup TLS area of a new thread and cleanup at exit.Siva Chandra Reddy
Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D129543
2022-07-13[libc][NFC] Move thread platform data pointer to thread attributes.Siva Chandra Reddy
Along the way, added constexpr constructors to the Thread data structures.
2022-06-27[libc][NFC] Make the support thread library an object library.Siva Chandra Reddy
It was previously a header library. Making it an object library will allow us to declare thread local variables which can used to setup a thread's self object.
2022-06-24[libc][NFC] Remove the templatization from the linux implementation of thread.Siva Chandra Reddy
This enables setting up a single "self" thread object to be returned by API like thrd_self and pthread_self.
2022-04-07[libc] Add a linux Thread class in __support/threads.Siva Chandra Reddy
This change is essentially a mechanical change which moves the thread creation and join implementations from src/threads/linux to src/__support/threads/linux/thread.h. The idea being that, in future, a pthread implementation can reuse the common thread implementations in src/__support/threads. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D123287