Module Name: src
Committed By: uwe
Date: Mon Dec 16 22:22:11 UTC 2019
Modified Files:
src/lib/libpthread: pthread_rwlock.c
Log Message:
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@.
To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/lib/libpthread/pthread_rwlock.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libpthread/pthread_rwlock.c
diff -u src/lib/libpthread/pthread_rwlock.c:1.35 src/lib/libpthread/pthread_rwlock.c:1.36
--- src/lib/libpthread/pthread_rwlock.c:1.35 Sun Dec 15 23:13:33 2019
+++ src/lib/libpthread/pthread_rwlock.c Mon Dec 16 22:22:11 2019
@@ -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;