Kernel: Optimize futexes
Add support for processor local futexes. These work the exact same way as global ones, but only lock a process specific lock and use a process specific hash map. Also reduce the time futex lock is held. There was no need to hold the global lock while validating addresses in the process' address space.
This commit is contained in:
@@ -884,9 +884,11 @@ int pthread_mutex_unlock(pthread_mutex_t* mutex)
|
||||
mutex->lock_depth--;
|
||||
if (mutex->lock_depth == 0)
|
||||
{
|
||||
const int op = FUTEX_WAKE | (mutex->attr.shared ? 0 : FUTEX_PRIVATE);
|
||||
|
||||
BAN::atomic_store(mutex->futex, 0, BAN::memory_order_release);
|
||||
if (BAN::atomic_load(mutex->waiters))
|
||||
futex(FUTEX_WAKE, &mutex->futex, 1, nullptr);
|
||||
futex(op, &mutex->futex, 1, nullptr);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -28,8 +28,9 @@ int sem_getvalue(sem_t* __restrict sem, int* __restrict sval)
|
||||
int sem_post(sem_t* sem)
|
||||
{
|
||||
const auto old = BAN::atomic_fetch_add(sem->value, 1);
|
||||
const int op = FUTEX_WAKE | (sem->shared ? 0 : FUTEX_PRIVATE);
|
||||
if (old == 0)
|
||||
futex(FUTEX_WAKE, &sem->value, 1, nullptr);
|
||||
futex(op, &sem->value, 1, nullptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user