summaryrefslogtreecommitdiff
path: root/Libraries/LibPthread/pthread.h
AgeCommit message (Collapse)Author
2021-01-12Libraries: Move to Userland/Libraries/Andreas Kling
2021-01-01LibPthread: Implement destruction of pthread_keysAndrew Kaster
Add a function to destroy any keys that were set on the current thread using the algorithm from Dr. POSIX's pthread_key_create. Add some defines to pthread.h for pthread key use, and implement pthread_key_delete. It has a prototype in pthread.h, but any program trying to actually use it would be in for a link-time surprise. Currently, keys are destroyed either via global destructors, with the s_key_destroyer object, or in exit_thread. exit_thread is invoked by pthread_exit, and transitively by pthread_create, via the pthread_create_helper that ensures all threads created with the pthread API properly clean up for themselves when they exit gracefully. A future patch might make s_key_destroyer a C++11 thread_local instead, assuming we get thread_local and thread_local destructors working.
2020-12-26Everywhere: void arguments to C functionsLenny Maiorani
Problem: - C functions with no arguments require a single `void` in the argument list. Solution: - Put the `void` in the argument list of functions in C header files.
2020-12-21Kernel: Improve time keeping and dramatically reduce interrupt loadTom
This implements a number of changes related to time: * If a HPET is present, it is now used only as a system timer, unless the Local APIC timer is used (in which case the HPET timer will not trigger any interrupts at all). * If a HPET is present, the current time can now be as accurate as the chip can be, independently from the system timer. We now query the HPET main counter for the current time in CPU #0's system timer interrupt, and use that as a base line. If a high precision time is queried, that base line is used in combination with quering the HPET timer directly, which should give a much more accurate time stamp at the expense of more overhead. For faster time stamps, the more coarse value based on the last interrupt will be returned. This also means that any missed interrupts should not cause the time to drift. * The default system interrupt rate is reduced to about 250 per second. * Fix calculation of Thread CPU usage by using the amount of ticks they used rather than the number of times a context switch happened. * Implement CLOCK_REALTIME_COARSE and CLOCK_MONOTONIC_COARSE and use it for most cases where precise timestamps are not needed.
2020-12-21Everywhere: Switch from (void) to [[maybe_unused]] (#4473)Lenny Maiorani
Problem: - `(void)` simply casts the expression to void. This is understood to indicate that it is ignored, but this is really a compiler trick to get the compiler to not generate a warning. Solution: - Use the `[[maybe_unused]]` attribute to indicate the value is unused. Note: - Functions taking a `(void)` argument list have also been changed to `()` because this is not needed and shows up in the same grep command.
2020-11-24LibPthread: Implement pthread_once()Sergey Bugaev
The implementation uses atomics and futexes (yay!) and is heavily based on the implementation I did for my learning project named "Let's write synchronization primitives" [0]. That project, in fact, started when I tried to implement pthread_once() for Serenity (because it was needed for another project of mine, stay tuned ;) ) and was not very sure I got every case right. So now, after learning some more about code patterns around atomics and futexes, I am reasonably sure, and it's time to contribute the implementation of pthread_once() to Serenity :^) [0] To be published at https://github.com/bugaevc/lets-write-sync-primitives
2020-09-25Meta+LibHTTP through LibWeb: Make clang-format-10 cleanBen Wiederhake
2020-07-21LibPThread: Make pthread_exit a noreturn functionMuhammad Zahalqa
LibPThread: mark pthread_exit a noreturn function using compiler attributes LibThread: remove a call to pthread_exit from Thread::start lambda expression as it make the return of teh lambda unreachable.
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2020-01-11LibPthread: Fix incompatible pthread_setname_np(), pthread_getname_np()Andreas Kling
Other implementations of pthread_setname_np() do not take the name length as an argument. For pthread_getname_np(), other implementations take the buffer size as a size_t. This patch brings us in line with other implementations.
2019-12-25Kernel+LibPthread+LibC: Add a naive futex and use it for pthread_cond_tAndreas Kling
This patch implements a simple version of the futex (fast userspace mutex) API in the kernel and uses it to make the pthread_cond_t API's block instead of busily sched_yield(). An arbitrary userspace address is passed to the kernel as a "token" that identifies the futex and you can then FUTEX_WAIT and FUTEX_WAKE that specific userspace address. FUTEX_WAIT corresponds to pthread_cond_wait() and FUTEX_WAKE is used for pthread_cond_signal() and pthread_cond_broadcast(). I'm pretty sure I'm missing something in this implementation, but it's hopefully okay for a start. :^)
2019-12-22LibPthread+LibC: Support PTHREAD_MUTEX_RECURSIVEAndreas Kling
This allows SDL to build against our native recursive mutex instead of providing its own. Also it's just a nice feature to have. :^)
2019-12-08LibPThread: Add pthread_set/getname_npAndrew Kaster
These wrappers call the set_thread_name and get_thread_name syscalls respectively.
2019-12-07LibPthread: Add stubs for pthread_{get,set}schedparam()Andreas Kling
These should be the last thing needed to make SDL build with threads support. I think we can survive just fine with stubs of these for now, especially given that the kernel doesn't care super much about thread priorities anyway.
2019-12-07LibPthread: Implement condition variablesAndreas Kling
This feels like a pretty naive implementation, but I think it can work. Basically each waiter creates an object on its stack that is then added to a linked list inside by the pthread_cond_t. Signalling is then done by walking the list and unsetting the "waiting" flag on as many of the waiters as you like.
2019-12-01LibPthread: Remove some duplicate declarations in pthread.hAndreas Kling
2019-11-18Kernel+LibPthread: pthread_create handles pthread_attr_tAndrew Kaster
Add an initial implementation of pthread attributes for: * detach state (joinable, detached) * schedule params (just priority) * guard page size (as skeleton) (requires kernel support maybe?) * stack size and user-provided stack location (4 or 8 MB only, must be aligned) Add some tests too, to the thread test program. Also, LibC: Move pthread declarations to sys/types.h, where they belong.
2019-11-16LibPthread: Implement a basic first pthread mutexAndreas Kling
This patch adds these API's: - pthread_mutex_init() - pthread_mutex_lock() - pthread_mutex_unlock() No mutex attributes are supported yet, so we only do the simplest mutex wihout recursive locking.
2019-11-13LibPthread: Start working on a POSIX threading libraryAndreas Kling
This patch adds pthread_create() and pthread_exit(), which currently simply wrap our existing create_thread() and exit_thread() syscalls. LibThread is also ported to using LibPthread.