Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libpthread pthread__rwlock_spin - clarify the test.



details:   https://anonhg.NetBSD.org/src/rev/4c14a162504e
branches:  trunk
changeset: 466272:4c14a162504e
user:      uwe <uwe%NetBSD.org@localhost>
date:      Mon Dec 16 22:22:11 2019 +0000

description:
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:

 lib/libpthread/pthread_rwlock.c |  13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diffs (37 lines):

diff -r 24fa31136589 -r 4c14a162504e lib/libpthread/pthread_rwlock.c
--- a/lib/libpthread/pthread_rwlock.c   Mon Dec 16 20:59:39 2019 +0000
+++ b/lib/libpthread/pthread_rwlock.c   Mon Dec 16 22:22:11 2019 +0000
@@ -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_t thread;
        unsigned int i;
 
+       if ((owner & ~RW_THREAD) != RW_WRITE_LOCKED)
+               return 0;
+
        thread = (pthread_t)(owner & RW_THREAD);
-       if (thread == NULL || (owner & ~RW_THREAD) != RW_WRITE_LOCKED)
-               return 0;
-       if (thread->pt_lwpctl->lc_curcpu == LWPCTL_CPU_NONE ||
+       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;



Home | Main Index | Thread Index | Old Index