Make Cosmo mutexes competitive with Apple Libc

While we have always licked glibc and musl libc on gnu/systemd sadly the
Apple Libc implementation of pthread_mutex_t is better than ours. It may
be due to how the XNU kernel and M2 microprocessor are in league when it
comes to scheduling processes and the NSYNC behavior is being penalized.
We can solve this by leaning more heavily on ulock using Drepper's algo.
It's kind of ironic that Linux's official mutexes work terribly on Linux
but almost as good as Apple Libc if used on MacOS.
This commit is contained in:
Justine Tunney 2024-09-02 18:21:03 -07:00
parent 2ec413b5a9
commit 90460ceb3c
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
13 changed files with 349 additions and 202 deletions

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/dce.h"
#include "libc/intrin/atomic.h"
#include "libc/limits.h"
#include "libc/thread/thread.h"
@ -44,7 +45,7 @@ errno_t pthread_cond_broadcast(pthread_cond_t *cond) {
#if PTHREAD_USE_NSYNC
// favor *NSYNC if this is a process private condition variable
// if using Mike Burrows' code isn't possible, use a naive impl
if (!cond->_pshared) {
if (!cond->_pshared && !IsXnuSilicon()) {
nsync_cv_broadcast((nsync_cv *)cond);
return 0;
}