summaryrefslogtreecommitdiff
path: root/libc/src/threads/linux
AgeCommit message (Collapse)Author
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-05-31[libc] rework mutex (#92168)Schrodinger ZHU Yifan
2024-05-21[libc][__support] move CndVar to __support (#89329)Nick Desaulniers (paternity leave)
We should be able to reuse this between the implementation of C11 cnd_t condition variables and POSIX pthread_cond_t condition variables. The current implementation is hyper linux specific, making use of Futex. That obviously wont work outside of linux, so split the OS specific functions off into their own source outside of the header. Modifies the return values of the to-be-shared impl to return 0 on success and -1 on error. This pattern was shamelessly stolen from Bionic's [__bionic_thrd_error](https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/include/bits/threads_inlines.h#41). Fixes: #88580 Link: #88583
2024-05-09[libc] Replace `MutexLock` with `cpp::lock_guard` (#89340)Vlad Mishel
This PR address issue #89002. #### Changes in this PR * Added a simple implementation of `cpp::lock_guard` (an equivalent of `std::lock_guard`) in libc/src/__support/CPP inspired by the libstdc++ implementation * Added tests for `cpp::lock_guard` in /libc/test/src/__support/CPP/mutex_test.cpp * Replaced all references to `MutexLock` with `cpp::lock_guard` --------- Co-authored-by: Guillaume Chatelet <gchatelet@google.com>
2024-05-07[libc] clean up futex usage (#91163)Schrodinger ZHU Yifan
# Motivation Futex syscalls are widely used in our codebase as synchronization mechanism. Hence, it may be worthy to abstract out the most common routines (wait and wake). On the other hand, C++20 also provides `std::atomic_notify_one/std::atomic_wait/std::atomic_notify_all` which align with such functionalities. This PR introduces `Futex` as a subtype of `cpp::Atomic<FutexWordType>` with additional `notify_one/notify_all/wait` operations. Providing such wrappers also make future porting easier. For example, FreeBSD's `_umtx_op` and Darwin's `ulock` can be wrapped in a similar manner. ### Similar Examples 1. [bionic futex](https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/bionic/bionic_futex.cpp) 2. [futex in Rust's std](https://github.com/rust-lang/rust/blob/8cef37dbb67e9c80702925f19cf298c4203991e4/library/std/src/sys/pal/unix/futex.rs#L21)
2024-01-23[libc] remove redundant call_once (#79226)Nick Desaulniers
Missed cleanup from https://reviews.llvm.org/D134716. Fixes: #79220
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-08-29[libc] Fix the remaining old style includesPetr Hosek
These were omitted from previous cleanup changes. Differential Revision: https://reviews.llvm.org/D159066
2023-08-07[libc][cleanup] Fix most conversion warningsMichael Jones
This patch is large, but is almost entirely just adding casts to calls to syscall_impl. Much of the work was done programatically, with human checking when the syntax or types got confusing. Reviewed By: mcgrathr Differential Revision: https://reviews.llvm.org/D156950
2023-08-03[libc] Add support to compile some syscalls on 32 bit platformMikhail R. Gadelha
This patch adds a bunch of ifdefs to handle the 32 bit versions of some syscalls, which often only append a 64 to the name of the syscall (with exception of SYS_lseek -> SYS_llseek and SYS_futex -> SYS_futex_time64) This patch also tries to handle cases where wait4 is not available (as in riscv32): to implement wait, wait4 and waitpid when wait4 is not available, we check for alternative wait calls and ultimately rely on waitid to implement them all. In riscv32, only waitid is available, so we need it to support this platform. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D148371
2023-07-05[libc] Use the new style includesPetr Hosek
We should be using the standard includes. Differential Revision: https://reviews.llvm.org/D154529
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-09-30[libc] add syscall functionMichael Jones
Add the syscall wrapper function and tests. It's implemented using a macro to guarantee the minimum number of arguments. Reviewed By: sivachandra, lntue Differential Revision: https://reviews.llvm.org/D134919
2022-09-28[libc] Add implementation of pthread_once.Siva Chandra Reddy
The existing thrd_once function has been refactored so that the implementation can be shared between thrd_once and pthread_once functions. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D134716
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
2022-04-02[libc][NFC] Do not call mmap and munmap from thread functions.Siva Chandra Reddy
Instead, memory is allocated and deallocated using mmap and munmap syscalls directly. Reviewed By: lntue, michaelrj Differential Revision: https://reviews.llvm.org/D122876
2022-03-31[libc] Enable threads.h functions on aarch64.Siva Chandra
Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D122788
2022-03-18[libc][NFC] Add the platform independent file target only if mutex is available.Siva Chandra Reddy
The platform independent file implementation is not an entrypoint so it cannot be excluded via the entrypoints.txt file. Hence, we need a special treatment to exclude it from the build. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D121947
2022-03-04[libc][NFC] Add a platform independent thread support library.Siva Chandra Reddy
The idea is that, other parts of the libc which require thread/lock support will be able to use this platform independent setup. With this change, only the linux implementation of a mutex type has been moved to the new library. Because of this, there is some duplication between the new library and src/threads/linux. A follow up change will move all of src/threads/linux to the new library. The duplication should be eliminated with that move. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D120795
2022-03-04[libc] Make the errno macro resolve to the thread local variable directly.Siva Chandra Reddy
With modern architectures having a thread pointer and language supporting thread locals, there is no reason to use a function intermediary to access the thread local errno value. The entrypoint corresponding to errno has been replaced with an object library as there is no formal entrypoint for errno anymore. Reviewed By: jeffbailey, michaelrj Differential Revision: https://reviews.llvm.org/D120920
2022-03-01[libc] Remove the remaining uses of stdatomic.h.Siva Chandra Reddy
New methods to the Atomic class have been added as required. Futex related types have been consolidated at a common place. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D120705
2022-02-28[libc] Add a class "Atomic" as a simple equivalent of std::atomic.Siva Chandra Reddy
Only the methods currently required by the libc have been added. Most of the existing uses of atomic operations have been switched over to this new class. A future change will clean up the rest of uses. This change now allows building mutex and condition variable code with a C++ compiler which does not have stdatomic.h, for example g++. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D120642
2021-12-22[libc] Move the x86_64 syscall functions to OSUtil.Siva Chandra Reddy
Reviewed By: michaelrj, lntue Differential Revision: https://reviews.llvm.org/D116177
2021-12-07[libc] apply new lint rulesMichael Jones
This patch applies the lint rules described in the previous patch. There was also a significant amount of effort put into manually fixing things, since all of the templated functions, or structs defined in /spec, were not updated and had to be handled manually. Reviewed By: sivachandra, lntue Differential Revision: https://reviews.llvm.org/D114302
2021-09-28[libc] Add implementations of the C standard condition variable functions.Siva Chandra Reddy
Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D108948
2021-09-01[libc] Add a skeleton for C standard condition variable functions.Siva Chandra Reddy
This patch adds a skeleton as a preparatory step for the next patch which adds the actual implementations of the condition variable functions. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D108947
2021-08-30[libc] Add mtx_destroy which does nothing.Siva Chandra Reddy
There is not cleanup to be done for the mutex type so mtx_destroy does nothing.
2021-08-30[libc] Ensure the result of the clone syscall is not on stack in thrd_create.Siva Chandra Reddy
Also, added a call to munmap on error in thrd_create.
2021-08-30[libc][NFC] Add a check to catch mismatch in internal and public mutex types.Siva Chandra Reddy
2021-08-26[libc][NFC] Move the mutex implementation into a utility class.Siva Chandra Reddy
This allows others parts of the libc to use the mutex types without actually pulling in public function implementations. Along the way, few cleanups have been done, like using a uniform type to refer the linux futex word. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D108749
2021-08-23[libc] Add a multi-waiter mutex test.Siva Chandra Reddy
A corresponding adjustment to mtx_lock has also been made.
2021-05-05[libc] Normalize LIBC_TARGET_MACHINEGuillaume Chatelet
Current implementation defines LIBC_TARGET_MACHINE with the use of CMAKE_SYSTEM_PROCESSOR. Unfortunately CMAKE_SYSTEM_PROCESSOR is OS dependent and can produce different results. An evidence of this is the various matchers used to detect whether the architecture is x86. This patch normalizes LIBC_TARGET_MACHINE and renames it LIBC_TARGET_ARCHITECTURE. I've added many architectures but we may want to limit ourselves to x86 and ARM. Differential Revision: https://reviews.llvm.org/D101524
2021-01-09[libc][NFC] add includes for internal headers to all libc functionsMichael Jones
this will make sure that all of the functions are using the correct prototypes. Explained much better in the comments of this diff: https://reviews.llvm.org/D94195
2021-01-08[libc] Switch to use a macro which does not insert a section for every libc ↵Michael Jones
function. Summary: The new macro also inserts the C alias for the C++ implementations without needing an objcopy based post processing step. The CMake rules have been updated to reflect this. More CMake cleanup can be taken up in future rounds and appropriate TODOs have been added for them. Reviewers: mcgrathr, sivachandra Subscribers:
2020-05-28[libc] Add implementation of call_once from threads.h.Siva Chandra Reddy
Reviewers: abrachet, maskray Differential Revision: https://reviews.llvm.org/D79828
2020-05-12[libc][Obvious] Fix deps of few threads targets.Siva Chandra Reddy
A missing dep has been added, and a few redundent deps have been removed.
2020-04-23[libc] Surround get_start_args_addr in __llvm_libc namespace.Paula Toth
Summary: Caught by libc-tidy from patch D77281. Reviewers: sivachandra Reviewed By: sivachandra Subscribers: tschuett, libc-commits Tags: #libc-project Differential Revision: https://reviews.llvm.org/D78700
2020-04-10[libc] Add fully-qualified target names.Siva Chandra Reddy
Only targets setup by the special LLVM libc rules now have fully qualified names. The naming style is similar to fully qualified names in Python. Reviewers: abrachet, PaulkaToast, phosek Differential Revision: https://reviews.llvm.org/D77340
2020-04-08[libc][NFC] Make all top of file comments consistent.Paula Toth
Summary: Made all header files consistent based of this documentation: https://llvm.org/docs/CodingStandards.html#file-headers. And did the same for all source files top of file comments. Reviewers: sivachandra, abrachet Reviewed By: sivachandra, abrachet Subscribers: MaskRay, tschuett, libc-commits Tags: #libc-project Differential Revision: https://reviews.llvm.org/D77533
2020-04-06[libc] NFC: Fix trivial typo in comments, documents, and messagesKazuaki Ishizaki
Differential Revision: https://reviews.llvm.org/D77462
2020-03-28[libc][NFC] Ensure internal implementation is in __llvm_libc namespaceAlex Brachet
Summary: In preparation for D76818. Reviewers: PaulkaToast, sivachandra, gchatelet Reviewed By: PaulkaToast, sivachandra Subscribers: MaskRay, tschuett, libc-commits Differential Revision: https://reviews.llvm.org/D76967
2020-03-09[libc] Add simple implementations of mtx_lock and mtx_unlock.Siva Chandra Reddy
These functions only support locking and unlocking of plain mutexes. They will be extended in future changes to handled recursive and timed mutexes. Reviewers: phosek Differential Revision: https://reviews.llvm.org/D74653
2020-03-09[libc] Take 2: Add linux implementations of thrd_create and thrd_join functions.Siva Chandra Reddy
The following are the differences from the first version: 1. The kernel does not copy the stack for the new thread (it cannot). The previous version missed this fact. In this new version, the new thread's start args are copied on to the new stack in a known location so that the new thread can sniff them out. 2. A start args sniffer for x86_64 has been added. 2. Default stack size has been increased to 64KB. Reviewers: abrachet, phosek Differential Revision: https://reviews.llvm.org/D75818
2020-03-05[libc]Revert "Add linux implementations of thrd_create and thrd_join functions."Siva Chandra Reddy
This reverts commit abc040e9533011a62a25c93b07b4fc31c8a641f7 as the bots are failing because of this.
2020-03-05[libc] Add linux implementations of thrd_create and thrd_join functions.Siva Chandra Reddy
Reviewers: abrachet, phosek Differential Revision: https://reviews.llvm.org/D75380