Cleanup inline locking code

This commit is contained in:
Justine Tunney 2023-11-29 00:36:22 -08:00
parent 96185e1ac0
commit 4427581a05
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
12 changed files with 48 additions and 74 deletions

View file

@ -16,9 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/intrin/atomic.h"
#include "libc/intrin/strace.internal.h"
#include "libc/thread/thread.h"
/**
@ -39,24 +37,9 @@
* @see pthread_spin_unlock
* @see pthread_spin_init
*/
errno_t(pthread_spin_lock)(pthread_spinlock_t *spin) {
int x;
#if defined(SYSDEBUG) && _LOCKTRACE
for (;;) {
x = atomic_exchange_explicit(&spin->_lock, 1, memory_order_acquire);
if (!x) {
LOCKTRACE("pthread_spin_lock(%t)", spin);
break;
}
unassert(x == 1);
LOCKTRACE("pthread_spin_lock(%t) trying...", spin);
errno_t pthread_spin_lock(pthread_spinlock_t *spin) {
while (atomic_exchange_explicit(&spin->_lock, 1, memory_order_acquire)) {
pthread_pause_np();
}
#else
for (;;) {
x = atomic_exchange_explicit(&spin->_lock, 1, memory_order_acquire);
if (!x) break;
unassert(x == 1);
}
#endif
return 0;
}