
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. :^)
38 lines
909 B
C++
38 lines
909 B
C++
#include <Kernel/Syscall.h>
|
|
#include <errno.h>
|
|
#include <serenity.h>
|
|
|
|
extern "C" {
|
|
|
|
int module_load(const char* path, size_t path_length)
|
|
{
|
|
int rc = syscall(SC_module_load, path, path_length);
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
}
|
|
|
|
int module_unload(const char* name, size_t name_length)
|
|
{
|
|
int rc = syscall(SC_module_unload, name, name_length);
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
}
|
|
|
|
int profiling_enable(pid_t pid)
|
|
{
|
|
int rc = syscall(SC_profiling_enable, pid);
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
}
|
|
|
|
int profiling_disable(pid_t pid)
|
|
{
|
|
int rc = syscall(SC_profiling_disable, pid);
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
}
|
|
|
|
int futex(int32_t* userspace_address, int futex_op, int32_t value, const struct timespec* timeout)
|
|
{
|
|
Syscall::SC_futex_params params { userspace_address, futex_op, value, timeout };
|
|
int rc = syscall(SC_futex, ¶ms);
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
}
|
|
|
|
}
|