summaryrefslogtreecommitdiff
path: root/lib/libpthread
diff options
context:
space:
mode:
authoruwe <uwe@NetBSD.org>2019-12-16 22:22:11 +0000
committeruwe <uwe@NetBSD.org>2019-12-16 22:22:11 +0000
commitd6f7de49fc523d076f19562807c46fd1f3dda62e (patch)
treed17154787ff5fbd65a1fc729f801023ee31314e9 /lib/libpthread
parent362d0d0f7fd653f9c8b1f79256f530a4527eb4f6 (diff)
pthread__rwlock_spin - clarify the test.
It's more pedantically correct to check RW_WRITE_LOCKED before obtaining the thread id of the owner. And since there must be an owner annotate the guard NULL check as unlinkely. No functional change intended. Ok ad@.
Diffstat (limited to 'lib/libpthread')
-rw-r--r--lib/libpthread/pthread_rwlock.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/libpthread/pthread_rwlock.c b/lib/libpthread/pthread_rwlock.c
index d5427132ddf..e5eda990c5b 100644
--- a/lib/libpthread/pthread_rwlock.c
+++ b/lib/libpthread/pthread_rwlock.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_rwlock.c,v 1.35 2019/12/15 23:13:33 uwe Exp $ */
+/* $NetBSD: pthread_rwlock.c,v 1.36 2019/12/16 22:22:11 uwe Exp $ */
/*-
* Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_rwlock.c,v 1.35 2019/12/15 23:13:33 uwe Exp $");
+__RCSID("$NetBSD: pthread_rwlock.c,v 1.36 2019/12/16 22:22:11 uwe Exp $");
#include <sys/types.h>
#include <sys/lwpctl.h>
@@ -134,12 +134,15 @@ pthread__rwlock_spin(uintptr_t owner)
pthread_t thread;
unsigned int i;
- thread = (pthread_t)(owner & RW_THREAD);
- if (thread == NULL || (owner & ~RW_THREAD) != RW_WRITE_LOCKED)
+ if ((owner & ~RW_THREAD) != RW_WRITE_LOCKED)
return 0;
- if (thread->pt_lwpctl->lc_curcpu == LWPCTL_CPU_NONE ||
+
+ thread = (pthread_t)(owner & RW_THREAD);
+ if (__predict_false(thread == NULL) ||
+ thread->pt_lwpctl->lc_curcpu == LWPCTL_CPU_NONE ||
thread->pt_blocking)
return 0;
+
for (i = 128; i != 0; i--)
pthread__rwlock_pause();
return 1;