[libc++] Do not yield from __sp_mut::lock()
authorLouis Dionne <ldionne.2@gmail.com>
Thu, 26 May 2022 21:42:06 +0000 (17:42 -0400)
committerLouis Dionne <ldionne.2@gmail.com>
Mon, 13 Jun 2022 15:48:13 +0000 (11:48 -0400)
commit5b386ac912eae3fad455df71ce226963fc97cdeb
tree71e3842857397923b9aca3f1485e7c6cfe2d86a6
parent4a8305ce856b6f4d2e49f3100226d00b402dff86
[libc++] Do not yield from __sp_mut::lock()

Instead of trying to be clever and design our own locking primitive,
simply rely on the OS-provided implementation to do the right thing.

Indeed, manually yielding to the OS does not provide the necessary
information for it to make good prioritization decisions. For example,
if a thread with higher priority yields while waiting for a lock held
by a thread with lower priority but the system is contended, it is
possible for the thread with lower priority to not run until the higher
priority thread has yielded 16 times and goes for __libcpp_mutex_lock().
Once that happens, the OS can bump the priority of the thread that
currently holds the lock to unblock everyone. So instead, we might as
well give the system all the information from the start so it can make
appropriate decisions.

As a fly-by change, also increase the number of locks in the table.
The size increase is modest, but has the potential to half the amount
of contention on those locks.

rdar://93598606

Differential Revision: https://reviews.llvm.org/D126882
libcxx/src/memory.cpp