On Wed Jul 10 20:16:10 2024 +0000, Alfred Agrell wrote:
While this implementation works, it is inefficient when releasing an uncontended lock: releasing the lock involves making a system call to futex_wake, even though there is no thread waiting for the lock. ~quote from your github link If there are no waiters, then there's nobody to wake up, and the syscall does nothing - but merely entering a syscall takes a lot longer than an atomic operation or two. There's a better implementation in that exact repo. While 3.6ms is indeed less than 5.7ms, that's just a synthetic benchmark containing the mutex and exactly nothing else. I'm curious if you can find any benchmark that shows an improvement to Wine itself, or if the difference becomes too small to measure. I agree with extracting this thing from winewayland. Mutexes are common, improving them for just one small piece is a weird choice. However, unlike winewayland, ntdll runs on mac, which doesn't have futexes, so you need to keep the pthread path working.
@Alcaro I made an even faster implementation of the mutex.
```text Time elapsed: t1=3.191000ms, t2=5.786000ms ```
Thanks to the article `Futexes Are Tricky` by `Ulrich Drepper` from `Red Hat, Inc.`
https://dept-info.labri.fr/~denis/Enseignement/2008-IR/Articles/01-futex.pdf