Index: conf/files =================================================================== RCS file: /cvs/src/sys/conf/files,v retrieving revision 1.629 diff -u -p -r1.629 files --- conf/files 6 Sep 2016 19:48:44 -0000 1.629 +++ conf/files 9 Sep 2016 01:40:42 -0000 @@ -692,7 +692,6 @@ file kern/subr_hibernate.c hibernate file kern/subr_log.c file kern/subr_poison.c diagnostic file kern/subr_pool.c -file kern/subr_tree.c file kern/dma_alloc.c file kern/subr_prf.c file kern/subr_prof.c Index: net/if_pppx.c =================================================================== RCS file: /cvs/src/sys/net/if_pppx.c,v retrieving revision 1.53 diff -u -p -r1.53 if_pppx.c --- net/if_pppx.c 5 Sep 2016 07:41:22 -0000 1.53 +++ net/if_pppx.c 9 Sep 2016 01:40:42 -0000 @@ -1,4 +1,4 @@ -/* $OpenBSD: if_pppx.c,v 1.53 2016/09/05 07:41:22 dlg Exp $ */ +/* $OpenBSD: if_pppx.c,v 1.52 2016/08/23 12:37:11 dlg Exp $ */ /* * Copyright (c) 2010 Claudio Jeker @@ -139,10 +139,12 @@ struct pppx_if_key { int pxik_protocol; }; +int pppx_if_cmp(struct pppx_if *, struct pppx_if *); + struct pppx_if { struct pppx_if_key pxi_key; /* must be first in the struct */ - RBT_ENTRY(pppx_if) pxi_entry; + RB_ENTRY(pppx_if) pxi_entry; LIST_ENTRY(pppx_if) pxi_list; int pxi_unit; @@ -152,15 +154,9 @@ struct pppx_if { struct pipex_iface_context pxi_ifcontext; }; -static inline int -pppx_if_cmp(const struct pppx_if *a, const struct pppx_if *b) -{ - return memcmp(&a->pxi_key, &b->pxi_key, sizeof(a->pxi_key)); -} - struct rwlock pppx_ifs_lk = RWLOCK_INITIALIZER("pppxifs"); -RBT_HEAD(pppx_ifs, pppx_if) pppx_ifs = RBT_INITIALIZER(&pppx_ifs); -RBT_PROTOTYPE(pppx_ifs, pppx_if, pxi_entry, pppx_if_cmp); +RB_HEAD(pppx_ifs, pppx_if) pppx_ifs = RB_INITIALIZER(&pppx_ifs); +RB_PROTOTYPE(pppx_ifs, pppx_if, pxi_entry, pppx_if_cmp); int pppx_if_next_unit(void); struct pppx_if *pppx_if_find(struct pppx_dev *, int, int); @@ -612,6 +608,12 @@ pppxclose(dev_t dev, int flags, int mode } int +pppx_if_cmp(struct pppx_if *a, struct pppx_if *b) +{ + return memcmp(&a->pxi_key, &b->pxi_key, sizeof(a->pxi_key)); +} + +int pppx_if_next_unit(void) { struct pppx_if *pxi; @@ -622,7 +624,7 @@ pppx_if_next_unit(void) /* this is safe without splnet since we're not modifying it */ do { int found = 0; - RBT_FOREACH(pxi, pppx_ifs, &pppx_ifs) { + RB_FOREACH(pxi, pppx_ifs, &pppx_ifs) { if (pxi->pxi_unit == unit) { found = 1; break; @@ -647,7 +649,7 @@ pppx_if_find(struct pppx_dev *pxd, int s s->pxi_key.pxik_protocol = protocol; rw_enter_read(&pppx_ifs_lk); - p = RBT_FIND(pppx_ifs, &pppx_ifs, s); + p = RB_FIND(pppx_ifs, &pppx_ifs, s); rw_exit_read(&pppx_ifs_lk); free(s, M_DEVBUF, 0); @@ -828,7 +830,7 @@ pppx_add_session(struct pppx_dev *pxd, s pxi->pxi_dev = pxd; /* this is safe without splnet since we're not modifying it */ - if (RBT_FIND(pppx_ifs, &pppx_ifs, pxi) != NULL) { + if (RB_FIND(pppx_ifs, &pppx_ifs, pxi) != NULL) { pool_put(pppx_if_pl, pxi); error = EADDRINUSE; goto out; @@ -874,7 +876,7 @@ pppx_add_session(struct pppx_dev *pxd, s #endif SET(ifp->if_flags, IFF_RUNNING); - if (RBT_INSERT(pppx_ifs, &pppx_ifs, pxi) != NULL) + if (RB_INSERT(pppx_ifs, &pppx_ifs, pxi) != NULL) panic("pppx_ifs modified while lock was held"); LIST_INSERT_HEAD(&pxd->pxd_pxis, pxi, pxi_list); @@ -982,7 +984,7 @@ pppx_if_destroy(struct pppx_dev *pxd, st if_detach(ifp); rw_enter_write(&pppx_ifs_lk); - if (RBT_REMOVE(pppx_ifs, &pppx_ifs, pxi) == NULL) + if (RB_REMOVE(pppx_ifs, &pppx_ifs, pxi) == NULL) panic("pppx_ifs modified while lock was held"); LIST_REMOVE(pxi, pxi_list); rw_exit_write(&pppx_ifs_lk); @@ -1126,4 +1128,4 @@ pppx_if_ioctl(struct ifnet *ifp, u_long return (error); } -RBT_GENERATE(pppx_ifs, pppx_if, pxi_entry, pppx_if_cmp); +RB_GENERATE(pppx_ifs, pppx_if, pxi_entry, pppx_if_cmp); Index: sys/tree.h =================================================================== RCS file: /cvs/src/sys/sys/tree.h,v retrieving revision 1.18 diff -u -p -r1.18 tree.h --- sys/tree.h 6 Sep 2016 06:56:30 -0000 1.18 +++ sys/tree.h 9 Sep 2016 01:40:43 -0000 @@ -745,226 +745,4 @@ name##_RB_MINMAX(struct name *head, int ((x) != NULL) && ((y) = name##_RB_PREV(x), 1); \ (x) = (y)) - -/* - * Copyright (c) 2016 David Gwynne - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -struct rb_type { - int (*t_compare)(const void *, const void *); - void (*t_augment)(void *); - unsigned int t_offset; /* offset of rb_entry in type */ -}; - -struct rb_tree { - struct rb_entry *rbt_root; -}; - -struct rb_entry { - struct rb_entry *rbe_parent; - struct rb_entry *rbe_left; - struct rb_entry *rbe_right; - unsigned int rbe_color; -}; - -#define RBT_HEAD(_name, _type) \ -struct _name { \ - struct rb_tree rbh_root; \ -} - -#define RBT_ENTRY(_type) struct rb_entry - -#ifdef _KERNEL -#include /* for NULL */ - -static inline void -_rb_init(struct rb_tree *rbt) -{ - rbt->rbt_root = NULL; -} - -static inline int -_rb_empty(struct rb_tree *rbt) -{ - return (rbt->rbt_root == NULL); -} - -void *_rb_insert(const struct rb_type *, struct rb_tree *, void *); -void *_rb_remove(const struct rb_type *, struct rb_tree *, void *); -void *_rb_find(const struct rb_type *, struct rb_tree *, const void *); -void *_rb_nfind(const struct rb_type *, struct rb_tree *, const void *); -void *_rb_root(const struct rb_type *, struct rb_tree *); -void *_rb_min(const struct rb_type *, struct rb_tree *); -void *_rb_max(const struct rb_type *, struct rb_tree *); -void *_rb_next(const struct rb_type *, void *); -void *_rb_prev(const struct rb_type *, void *); -void *_rb_left(const struct rb_type *, void *); -void *_rb_right(const struct rb_type *, void *); -void *_rb_parent(const struct rb_type *, void *); -void *_rb_color(const struct rb_type *, void *); - -#define RBT_INITIALIZER(_head) { { NULL } } - -#define RBT_PROTOTYPE(_name, _type, _field, _cmp) \ -extern const struct rb_type *const _name##_RBT_TYPE; \ - \ -static inline void \ -_name##_RBT_INIT(struct _name *head) \ -{ \ - _rb_init(&head->rbh_root); \ -} \ - \ -static inline struct _type * \ -_name##_RBT_INSERT(struct _name *head, struct _type *elm) \ -{ \ - return _rb_insert(_name##_RBT_TYPE, &head->rbh_root, elm); \ -} \ - \ -static inline struct _type * \ -_name##_RBT_REMOVE(struct _name *head, struct _type *elm) \ -{ \ - return _rb_remove(_name##_RBT_TYPE, &head->rbh_root, elm); \ -} \ - \ -static inline struct _type * \ -_name##_RBT_FIND(struct _name *head, const struct _type *key) \ -{ \ - return _rb_find(_name##_RBT_TYPE, &head->rbh_root, key); \ -} \ - \ -static inline struct _type * \ -_name##_RBT_NFIND(struct _name *head, const struct _type *key) \ -{ \ - return _rb_nfind(_name##_RBT_TYPE, &head->rbh_root, key); \ -} \ - \ -static inline struct _type * \ -_name##_RBT_ROOT(struct _name *head) \ -{ \ - return _rb_root(_name##_RBT_TYPE, &head->rbh_root); \ -} \ - \ -static inline int \ -_name##_RBT_EMPTY(struct _name *head) \ -{ \ - return _rb_empty(&head->rbh_root); \ -} \ - \ -static inline struct _type * \ -_name##_RBT_MIN(struct _name *head) \ -{ \ - return _rb_min(_name##_RBT_TYPE, &head->rbh_root); \ -} \ - \ -static inline struct _type * \ -_name##_RBT_MAX(struct _name *head) \ -{ \ - return _rb_max(_name##_RBT_TYPE, &head->rbh_root); \ -} \ - \ -static inline struct _type * \ -_name##_RBT_NEXT(struct _type *elm) \ -{ \ - return _rb_next(_name##_RBT_TYPE, elm); \ -} \ - \ -static inline struct _type * \ -_name##_RBT_PREV(struct _type *elm) \ -{ \ - return _rb_prev(_name##_RBT_TYPE, elm); \ -} \ - \ -static inline struct _type * \ -_name##_RBT_LEFT(struct _type *elm) \ -{ \ - return _rb_left(_name##_RBT_TYPE, elm); \ -} \ - \ -static inline struct _type * \ -_name##_RBT_RIGHT(struct _type *elm) \ -{ \ - return _rb_right(_name##_RBT_TYPE, elm); \ -} \ - \ -static inline struct _type * \ -_name##_RBT_PARENT(struct _type *elm) \ -{ \ - return _rb_parent(_name##_RBT_TYPE, elm); \ -} - -#define RBT_GENERATE_INTERNAL(_name, _type, _field, _cmp, _aug) \ -static int \ -_name##_RBT_COMPARE(const void *lptr, const void *rptr) \ -{ \ - const struct _type *l = lptr, *r = rptr; \ - return _cmp(l, r); \ -} \ -static const struct rb_type _name##_RBT_INFO = { \ - _name##_RBT_COMPARE, \ - _aug, \ - offsetof(struct _type, _field), \ -}; \ -const struct rb_type *const _name##_RBT_TYPE = &_name##_RBT_INFO - -#define RBT_GENERATE_AUGMENT(_name, _type, _field, _cmp, _aug) \ -static void \ -_name##_RBT_AUGMENT(void *ptr) \ -{ \ - struct _type *p = ptr; \ - return _aug(p); \ -} \ -RBT_GENERATE_INTERNAL(_name, _type, _field, _cmp, _name##_RBT_AUGMENT) - -#define RBT_GENERATE(_name, _type, _field, _cmp) \ - RBT_GENERATE_INTERNAL(_name, _type, _field, _cmp, NULL) - -#define RBT_INIT(_name, _head) _name##_RBT_INIT(_head) -#define RBT_INSERT(_name, _head, _elm) _name##_RBT_INSERT(_head, _elm) -#define RBT_REMOVE(_name, _head, _elm) _name##_RBT_REMOVE(_head, _elm) -#define RBT_FIND(_name, _head, _key) _name##_RBT_FIND(_head, _key) -#define RBT_NFIND(_name, _head, _key) _name##_RBT_NFIND(_head, _key) -#define RBT_ROOT(_name, _head) _name##_RBT_ROOT(_head) -#define RBT_EMPTY(_name, _head) _name##_RBT_EMPTY(_head) -#define RBT_MIN(_name, _head) _name##_RBT_MIN(_head) -#define RBT_MAX(_name, _head) _name##_RBT_MAX(_head) -#define RBT_NEXT(_name, _elm) _name##_RBT_NEXT(_elm) -#define RBT_PREV(_name, _elm) _name##_RBT_PREV(_elm) -#define RBT_LEFT(_name, _elm) _name##_RBT_LEFT(_elm) -#define RBT_RIGHT(_name, _elm) _name##_RBT_RIGHT(_elm) -#define RBT_PARENT(_name, _elm) _name##_RBT_PARENT(_elm) - -#define RBT_FOREACH(_e, _name, _head) \ - for ((_e) = RBT_MIN(_name, (_head)); \ - (_e) != NULL; \ - (_e) = RBT_NEXT(_name, (_e))) - -#define RBT_FOREACH_SAFE(_e, _name, _head, _n) \ - for ((_e) = RBT_MIN(_name, (_head)); \ - (_e) != NULL && ((_n) = RBT_NEXT(_name, (_e)), 1); \ - (_e) = (_n)) - -#define RBT_FOREACH_REVERSE(_e, _name, _head) \ - for ((_e) = RBT_MAX(_name, (_head)); \ - (_e) != NULL; \ - (_e) = RBT_PREV(_name, (_e))) - -#define RBT_FOREACH_REVERSE_SAFE(_e, _name, _head, _n) \ - for ((_e) = RBT_MAX(_name, (_head)); \ - (_e) != NULL && ((_n) = RBT_PREV(_name, (_e)), 1); \ - (_e) = (_n)) - -#endif /* _KERNEL */ - #endif /* _SYS_TREE_H_ */