summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC/pthread_integration.cpp
AgeCommit message (Collapse)Author
2021-07-06LibC: Only set owner on recursive mutexesSergey Bugaev
This lets us skip the gettid() calls on fast paths. Also, verify that futex_wake() succeeds.
2021-07-05LibC: Add __pthread_mutex_lock_pessimistic_np()Sergey Bugaev
This is a private function that locks the lock much like the regular pthread_mutex_lock(), but causes the corresponding unlock operation to always assume there may be other waiters. This is useful in case some waiters are made to wait on the mutex's futex directly, without going through pthread_mutex_lock(). This is going to be used by the condition variable implementation in the next commit.
2021-07-05LibC: Rewrite pthread_mutexSergey Bugaev
pthread_mutex is now an actual "sleeping" mutex, and not just a spinlock! It still has a fast path that only uses atomics and (in the successful case) returns immediately without sleeping. In case of contention, it calls futex_wait(), which lets the kernel scheduler put this thread to sleep, *and* lets it know exactly when to consider scheduling it again.
2021-06-02LibC: Use memory_order_acquire instead of memory_order_acq_relGunnar Beutner
Acquire ordering should be sufficient for pthread_mutex_lock and pthread_mutex_trylock.
2021-06-02LibC: Fix race condition in pthread_mutex_unlock()Gunnar Beutner
This ensures the store to mutex->lock doesn't get re-ordered before the store to mutex->owner which could otherwise result in a locked owner-less mutex if another thread tries to acquire the lock at the same time.
2021-06-02LibC: Remove reinterpret_cast in pthread_mutex_{try,}lockGunnar Beutner
2021-05-14LibC: Do not include errno.h inside unistd.hJean-Baptiste Boric
POSIX does not mandate this, therefore let's not do it.
2021-04-25LibC: Move the __pthread_mutex_trylock function to LibCGunnar Beutner
Let's move this to LibC because the dynamic loader depends on this function.
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-20LibC+LibPthread: Implement function forwarding for libpthreadGunnar Beutner
GCC will insert various calls to pthread functions when compiling C++ code with static initializers, even when the user doesn't link their program against libpthread explicitly. This is used to make static initializers thread-safe, e.g. when building a library that does not itself use thread functionality and thus does not link against libpthread - but is intended to be used with other code that does use libpthread explicitly. This makes these symbols available in libc.
2021-02-15LibC+LibPthread: Implement pthread_atfork()AnotherTest
This required a bit of rearchitecture, as pthread_atfork() required a mutex, and duplicating a mutex impl for it was silly. As such, this patch moves some standalone bits of pthread into LibC and uses those to implement atfork(). It should be noted that for programs that don't use atfork(), this mechanism only costs two atomic loads (as opposed to the normal mutex lock+unlock) :^)