Source-Changes-HG archive

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

[src/trunk]: src/lib/libpthread libpthread: replace the use of obsolete sys/t...



details:   https://anonhg.NetBSD.org/src/rev/7e7f74d31227
branches:  trunk
changeset: 782472:7e7f74d31227
user:      rmind <rmind%NetBSD.org@localhost>
date:      Sat Nov 03 23:42:27 2012 +0000

description:
libpthread: replace the use of obsolete sys/tree.h interface with rbtree(9).

diffstat:

 lib/libpthread/pthread.c     |  58 ++++++++++++++++++++++----------------------
 lib/libpthread/pthread_int.h |   6 ++--
 2 files changed, 32 insertions(+), 32 deletions(-)

diffs (162 lines):

diff -r b88596674ac0 -r 7e7f74d31227 lib/libpthread/pthread.c
--- a/lib/libpthread/pthread.c  Sat Nov 03 23:22:21 2012 +0000
+++ b/lib/libpthread/pthread.c  Sat Nov 03 23:42:27 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread.c,v 1.138 2012/11/03 03:10:35 christos Exp $   */
+/*     $NetBSD: pthread.c,v 1.139 2012/11/03 23:42:27 rmind Exp $      */
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread.c,v 1.138 2012/11/03 03:10:35 christos Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.139 2012/11/03 23:42:27 rmind Exp $");
 
 #define        __EXPOSE_STACK  1
 
@@ -49,6 +49,7 @@
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stddef.h>
 #include <string.h>
 #include <syslog.h>
 #include <ucontext.h>
@@ -59,12 +60,16 @@
 #include "pthread_int.h"
 
 pthread_rwlock_t pthread__alltree_lock = PTHREAD_RWLOCK_INITIALIZER;
-RB_HEAD(__pthread__alltree, __pthread_st) pthread__alltree;
+static rb_tree_t       pthread__alltree;
+
+static signed int      pthread__cmp(void *, const void *, const void *);
 
-#ifndef lint
-static int     pthread__cmp(struct __pthread_st *, struct __pthread_st *);
-RB_PROTOTYPE_STATIC(__pthread__alltree, __pthread_st, pt_alltree, pthread__cmp)
-#endif
+static const rb_tree_ops_t pthread__alltree_ops = {
+       .rbto_compare_nodes = pthread__cmp,
+       .rbto_compare_key = pthread__cmp,
+       .rbto_node_offset = offsetof(struct __pthread_st, pt_alltree),
+       .rbto_context = NULL
+};
 
 static void    pthread__create_tramp(void *);
 static void    pthread__initthread(pthread_t);
@@ -176,7 +181,8 @@
        pthread_attr_init(&pthread_default_attr);
        PTQ_INIT(&pthread__allqueue);
        PTQ_INIT(&pthread__deadqueue);
-       RB_INIT(&pthread__alltree);
+
+       rb_tree_init(&pthread__alltree, &pthread__alltree_ops);
 
        /* Create the thread structure corresponding to main() */
        pthread__initmain(&first);
@@ -185,7 +191,7 @@
 
        first->pt_lid = _lwp_self();
        PTQ_INSERT_HEAD(&pthread__allqueue, first, pt_allq);
-       RB_INSERT(__pthread__alltree, &pthread__alltree, first);
+       (void)rb_tree_insert_node(&pthread__alltree, first);
 
        if (_lwp_ctl(LWPCTL_FEATURE_CURCPU, &first->pt_lwpctl) != 0) {
                err(1, "_lwp_ctl");
@@ -458,7 +464,7 @@
                /* Add to list of all threads. */
                pthread_rwlock_wrlock(&pthread__alltree_lock);
                PTQ_INSERT_TAIL(&pthread__allqueue, newthread, pt_allq);
-               RB_INSERT(__pthread__alltree, &pthread__alltree, newthread);
+               (void)rb_tree_insert_node(&pthread__alltree, newthread);
                pthread_rwlock_unlock(&pthread__alltree_lock);
 
                /* Will be reset by the thread upon exit. */
@@ -933,24 +939,20 @@
 /*
  * POSIX requires that certain functions return an error rather than
  * invoking undefined behavior even when handed completely bogus
- * pthread_t values, e.g. stack garbage or (pthread_t)666. This
- * utility routine searches the list of threads for the pthread_t
- * value without dereferencing it.
+ * pthread_t values, e.g. stack garbage.
  */
 int
 pthread__find(pthread_t id)
 {
        pthread_t target;
+       int error;
 
        pthread_rwlock_rdlock(&pthread__alltree_lock);
-       /* LINTED */
-       target = RB_FIND(__pthread__alltree, &pthread__alltree, id);
+       target = rb_tree_find_node(&pthread__alltree, id);
+       error = (target && target->pt_state != PT_STATE_DEAD) ? 0 : ESRCH;
        pthread_rwlock_unlock(&pthread__alltree_lock);
 
-       if (target == NULL || target->pt_state == PT_STATE_DEAD)
-               return ESRCH;
-
-       return 0;
+       return error;
 }
 
 
@@ -1300,20 +1302,18 @@
        pthread__main.pt_tls->tcb_pthread = &pthread__main;
 }
 
-#ifndef lint
-static int
-pthread__cmp(struct __pthread_st *a, struct __pthread_st *b)
+static signed int
+pthread__cmp(void *ctx, const void *n1, const void *n2)
 {
+       const uintptr_t const p1 = (const uintptr_t)n1;
+       const uintptr_t const p2 = (const uintptr_t)n2;
 
-       if ((uintptr_t)a < (uintptr_t)b)
-               return (-1);
-       else if (a == b)
-               return 0;
-       else
+       if (p1 < p2)
+               return -1;
+       if (p1 > p2)
                return 1;
+       return 0;
 }
-RB_GENERATE_STATIC(__pthread__alltree, __pthread_st, pt_alltree, pthread__cmp)
-#endif
 
 /* Because getenv() wants to use locks. */
 char *
diff -r b88596674ac0 -r 7e7f74d31227 lib/libpthread/pthread_int.h
--- a/lib/libpthread/pthread_int.h      Sat Nov 03 23:22:21 2012 +0000
+++ b/lib/libpthread/pthread_int.h      Sat Nov 03 23:42:27 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_int.h,v 1.86 2012/08/16 04:49:47 matt Exp $    */
+/*     $NetBSD: pthread_int.h,v 1.87 2012/11/03 23:42:27 rmind Exp $   */
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -50,7 +50,7 @@
 #include "../../common/lib/libc/atomic/atomic_op_namespace.h"
 
 #include <sys/atomic.h>
-#include <sys/tree.h>
+#include <sys/rbtree.h>
 
 #include <limits.h>
 #include <lwp.h>
@@ -126,7 +126,7 @@
 
        /* LWP ID and entry on the list of all threads. */
        lwpid_t         pt_lid;
-       RB_ENTRY(__pthread_st) pt_alltree;
+       rb_node_t       pt_alltree;
        PTQ_ENTRY(__pthread_st) pt_allq;
        PTQ_ENTRY(__pthread_st) pt_deadq;
 



Home | Main Index | Thread Index | Old Index