Source-Changes-HG archive

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

[src/trunk]: src/lib/libpthread Use pthread__sched_sleepers() instead of iter...



details:   https://anonhg.NetBSD.org/src/rev/90e9e567e4f1
branches:  trunk
changeset: 542507:90e9e567e4f1
user:      nathanw <nathanw%NetBSD.org@localhost>
date:      Fri Jan 31 04:59:40 2003 +0000

description:
Use pthread__sched_sleepers() instead of iterating over sleep queues
ourself.

diffstat:

 lib/libpthread/pthread.c         |  15 +++++++--------
 lib/libpthread/pthread_barrier.c |   6 ++----
 lib/libpthread/pthread_cond.c    |  10 ++++------
 lib/libpthread/pthread_rwlock.c  |   7 +++----
 4 files changed, 16 insertions(+), 22 deletions(-)

diffs (155 lines):

diff -r bc7980c9abe2 -r 90e9e567e4f1 lib/libpthread/pthread.c
--- a/lib/libpthread/pthread.c  Fri Jan 31 04:58:57 2003 +0000
+++ b/lib/libpthread/pthread.c  Fri Jan 31 04:59:40 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread.c,v 1.7 2003/01/29 14:03:08 drochner Exp $     */
+/*     $NetBSD: pthread.c,v 1.8 2003/01/31 04:59:40 nathanw Exp $      */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -345,7 +345,7 @@
 void
 pthread_exit(void *retval)
 {
-       pthread_t self, joiner;
+       pthread_t self;
        struct pt_clean_t *cleanup;
        int nt;
 
@@ -397,11 +397,11 @@
                        /* Whoah, we're the last one. Time to go. */
                        exit(0);
                }
-               /* Wake up all the potential joiners. Only one can win.
+               /*
+                * Wake up all the potential joiners. Only one can win.
                 * (Can you say "Thundering Herd"? I knew you could.)
                 */
-               PTQ_FOREACH(joiner, &self->pt_joiners, pt_sleep)
-                   pthread__sched(self, joiner);
+               pthread__sched_sleepers(self, &self->pt_joiners);
                pthread__block(self, &self->pt_join_lock);
        }
 
@@ -505,7 +505,7 @@
 int
 pthread_detach(pthread_t thread)
 {
-       pthread_t self, joiner;
+       pthread_t self;
 
        self = pthread__self();
 
@@ -525,8 +525,7 @@
        thread->pt_flags |= PT_FLAG_DETACHED;
 
        /* Any joiners have to be punted now. */
-       PTQ_FOREACH(joiner, &thread->pt_joiners, pt_sleep)
-           pthread__sched(self, joiner);
+       pthread__sched_sleepers(self, &thread->pt_joiners);
 
        pthread_spinunlock(self, &thread->pt_join_lock);
 
diff -r bc7980c9abe2 -r 90e9e567e4f1 lib/libpthread/pthread_barrier.c
--- a/lib/libpthread/pthread_barrier.c  Fri Jan 31 04:58:57 2003 +0000
+++ b/lib/libpthread/pthread_barrier.c  Fri Jan 31 04:59:40 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_barrier.c,v 1.3 2003/01/25 00:47:06 nathanw Exp $      */
+/*     $NetBSD: pthread_barrier.c,v 1.4 2003/01/31 04:59:40 nathanw Exp $      */
 
 /*-
  * Copyright (c) 2001, 2003 The NetBSD Foundation, Inc.
@@ -163,7 +163,6 @@
         */
        if (barrier->ptb_curcount + 1 == barrier->ptb_initcount) {
                struct pthread_queue_t blockedq;
-               pthread_t signaled;
 
                SDPRINTF(("(barrier wait %p) Satisfied %p\n",
                    self, barrier));
@@ -173,8 +172,7 @@
                barrier->ptb_curcount = 0;
                barrier->ptb_generation++;
 
-               PTQ_FOREACH(signaled, &blockedq, pt_sleep)
-                       pthread__sched(self, signaled);
+               pthread__sched_sleepers(self, &blockedq);
 
                pthread_spinunlock(self, &barrier->ptb_lock);
 
diff -r bc7980c9abe2 -r 90e9e567e4f1 lib/libpthread/pthread_cond.c
--- a/lib/libpthread/pthread_cond.c     Fri Jan 31 04:58:57 2003 +0000
+++ b/lib/libpthread/pthread_cond.c     Fri Jan 31 04:59:40 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_cond.c,v 1.4 2003/01/31 04:26:50 nathanw Exp $ */
+/*     $NetBSD: pthread_cond.c,v 1.5 2003/01/31 04:59:40 nathanw Exp $ */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -226,7 +226,6 @@
        pthread_mutex_lock(mutex);
        pthread__testcancel(self);
 
-
        return retval;
 }
 
@@ -280,9 +279,9 @@
                if (PTQ_EMPTY(&cond->ptc_waiters))
                        cond->ptc_mutex = NULL;
 #endif
+               pthread_spinunlock(self, &cond->ptc_lock);
                if (signaled != NULL)
                        pthread__sched(self, signaled);
-               pthread_spinunlock(self, &cond->ptc_lock);
        }
 
        return 0;
@@ -292,7 +291,7 @@
 int
 pthread_cond_broadcast(pthread_cond_t *cond)
 {
-       pthread_t self, signaled;
+       pthread_t self;
        struct pthread_queue_t blockedq;
 #ifdef ERRORCHECK
        if ((cond == NULL) || (cond->ptc_magic != _PT_COND_MAGIC))
@@ -311,9 +310,8 @@
 #ifdef ERRORCHECK
                cond->ptc_mutex = NULL;
 #endif
-               PTQ_FOREACH(signaled, &blockedq, pt_sleep)
-                   pthread__sched(self, signaled);
                pthread_spinunlock(self, &cond->ptc_lock);
+               pthread__sched_sleepers(self, &blockedq);
        }
 
        return 0;
diff -r bc7980c9abe2 -r 90e9e567e4f1 lib/libpthread/pthread_rwlock.c
--- a/lib/libpthread/pthread_rwlock.c   Fri Jan 31 04:58:57 2003 +0000
+++ b/lib/libpthread/pthread_rwlock.c   Fri Jan 31 04:59:40 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_rwlock.c,v 1.2 2003/01/18 10:34:16 thorpej Exp $ */
+/*     $NetBSD: pthread_rwlock.c,v 1.3 2003/01/31 04:59:40 nathanw Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -378,7 +378,7 @@
 int
 pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
 {
-       pthread_t self, reader, writer;
+       pthread_t self, writer;
        struct pthread_queue_t blockedq;
 #ifdef ERRORCHECK
        if ((rwlock == NULL) || (rwlock->ptr_magic != _PT_RWLOCK_MAGIC))
@@ -421,8 +421,7 @@
        if (writer != NULL)
                pthread__sched(self, writer);
        else
-               PTQ_FOREACH(reader, &blockedq, pt_sleep)
-                       pthread__sched(self, reader);
+               pthread__sched_sleepers(self, &blockedq);
        
        return 0;
 }



Home | Main Index | Thread Index | Old Index