summaryrefslogtreecommitdiff
path: root/Libraries/LibPthread
AgeCommit message (Collapse)Author
2020-05-20Revert "Build: Include headers from LibC, LibM, and LibPthread with -isystem"Andreas Kling
This reverts commit c1eb744ff0a82cf6c8e3470ac10e2f417c7d9de2.
2020-05-20Build: Include headers from LibC, LibM, and LibPthread with -isystemAndrew Kaster
Make sure that userspace is always referencing "system" headers in a way that would build on target :). This means removing the explicit include_directories of Libraries/LibC in favor of having it export its headers as SYSTEM. Also remove a redundant include_directories of Libraries in the 'serenity build' part of the build script. It's already set at the top. This causes issues for the Kernel, and for crt0.o. These special cases are handled individually.
2020-05-14Build: Switch to CMake :^)Sergey Bugaev
Closes https://github.com/SerenityOS/serenity/issues/2080
2020-04-26LibPthread: Hookup abstime argument to pthread_cond_timedwaitBrian Gianforcaro
Now that the futex implementation actually supports timeouts, we can fix the LibPthread implementation of pthread_cond_timedwait to support the timeout argument.
2020-04-25LibPthread: implicitly call pthread_exit on return from start routine.Drew Stratford
Previously, when returning from a pthread's start_routine, we would segfault. Now we instead implicitly call pthread_exit as specified in the standard. pthread_create now creates a thread running the new pthread_create_helper, which properly manages the calling and exiting of the start_routine supplied to pthread_create. To accomplish this, the thread's stack initialization has been moved out of sys$create_thread and into the userspace function create_thread.
2020-03-08Userspace: Add missing #includes now that AK/StdLibExtras.h is smallerAndreas Kling
2020-02-06LibPthread: Install immediately after buildingAndreas Kling
2020-02-01LibPthread: Disable debug spam by defaultAndreas Kling
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.
2020-01-11Kernel: Use the Syscall string and buffer types moreAndreas Kling
While I was updating syscalls to stop passing null-terminated strings, I added some helpful struct types: - StringArgument { const char*; size_t; } - ImmutableBuffer<Data, Size> { const Data*; Size; } - MutableBuffer<Data, Size> { Data*; Size; } The Process class has some convenience functions for validating and optionally extracting the contents from these structs: - get_syscall_path_argument(StringArgument) - validate_and_copy_string_from_user(StringArgument) - validate(ImmutableBuffer) - validate(MutableBuffer) There's still so much code around this and I'm wondering if we should generate most of it instead. Possible nice little project.
2019-12-30Kernel: Refactor scheduler to use dynamic thread prioritiesAndreas Kling
Threads now have numeric priorities with a base priority in the 1-99 range. Whenever a runnable thread is *not* scheduled, its effective priority is incremented by 1. This is tracked in Thread::m_extra_priority. The effective priority of a thread is m_priority + m_extra_priority. When a runnable thread *is* scheduled, its m_extra_priority is reset to zero and the effective priority returns to base. This means that lower-priority threads will always eventually get scheduled to run, once its effective priority becomes high enough to exceed the base priority of threads "above" it. The previous values for ThreadPriority (Low, Normal and High) are now replaced as follows: Low -> 10 Normal -> 30 High -> 50 In other words, it will take 20 ticks for a "Low" priority thread to get to "Normal" effective priority, and another 20 to reach "High". This is not perfect, and I've used some quite naive data structures, but I think the mechanism will allow us to build various new and interesting optimizations, and we can figure out better data structures later on. :^)
2019-12-27LibPthread: Log debug info to debug console instead of stdout (#931)Valtteri Koskivuori
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: Okay I'm dumb, let's convert mutex locks into Atomic<u32>&Andreas Kling
2019-12-22LibPthread: Fix typo in pthread_mutex_lock()Andreas Kling
We were casting the pthread_mutex_t* instead of pthread_mutex_t::lock to an Atomic<u32>. This still worked fine, since "lock" is the first member of pthread_mutex_t.
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-20Build: clean up build system, use one shared Makefilejoshua stein
Allow everything to be built from the top level directory with just 'make', cleaned with 'make clean', and installed with 'make install'. Also support these in any particular subdirectory. Specifying 'make VERBOSE=1' will print each ld/g++/etc. command as it runs. Kernel and early host tools (IPCCompiler, etc.) are built as object.host.o so that they don't conflict with other things built with the cross-compiler.
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: Condition variables should use CLOCK_MONOTONIC by defaultAndreas Kling
It's the only clock we have at the moment, so it's a logical choice :^)
2019-12-07LibPthread: Mark the pthread_cond_t "waiting" flag as volatileAndreas Kling
Oops, this is not gonna work if the compiler can optimize out all the reads from this flag. :^)
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 simple thread-specific keysAndreas Kling
This patch adds pthread_key_create() and pthread_{get,set}specific(). There's a maximum of 64 thread-specific keys for simplicity. Key destructors are not invoked on thread exit.
2019-12-07LibPthread: Implement pthread_sigmask()Andreas Kling
2019-12-07Kernel+LibPthread: Implement pthread_detach()Andreas Kling
2019-12-07LibPthread: Implement pthread_mutexattr_init() and _destroy()Andreas Kling
2019-12-07LibPthread: Don't set errno in pthread functionsAndreas Kling
POSIX says that pthread API's don't set errno directly. If there is an error, it should be the return value from the function instead.
2019-12-07LibPthread: Implement pthread_mutex_trylock()Andreas Kling
2019-12-07LibPthread: Implement pthread_self()Andreas Kling
2019-12-07LibPthread: Implement pthread_mutex_destroy()Andreas Kling
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-17Kernel+LibPthread+LibC: Create secondary thread stacks in userspaceAndreas Kling
Have pthread_create() allocate a stack and passing it to the kernel instead of this work happening in the kernel. The more of this we can do in userspace, the better. This patch also unexposes the raw create_thread() and exit_thread() syscalls since they are now only used by LibPthread anyway.
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-14Kernel+LibPthread: Implement pthread_join()Andreas Kling
It's now possible to block until another thread in the same process has exited. We can also retrieve its exit value, which is whatever value it passed to pthread_exit(). :^)
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.