_prop_rb_tree_insert_node() now returns true/false to indicate if the

insertion succeeded.  Update existing usage that arranges for insertions
to always succeed to assert that they do.
This commit is contained in:
thorpej 2008-06-17 21:29:47 +00:00
parent b612638bbf
commit e0e4b153c9
4 changed files with 20 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: prop_dictionary.c,v 1.30 2008/05/24 14:32:48 yamt Exp $ */ /* $NetBSD: prop_dictionary.c,v 1.31 2008/06/17 21:29:47 thorpej Exp $ */
/*- /*-
* Copyright (c) 2006, 2007 The NetBSD Foundation, Inc. * Copyright (c) 2006, 2007 The NetBSD Foundation, Inc.
@ -268,6 +268,7 @@ _prop_dict_keysym_alloc(const char *key)
prop_dictionary_keysym_t opdk, pdk; prop_dictionary_keysym_t opdk, pdk;
const struct rb_node *n; const struct rb_node *n;
size_t size; size_t size;
bool rv;
/* /*
* Check to see if this already exists in the tree. If it does, * Check to see if this already exists in the tree. If it does,
@ -325,7 +326,8 @@ _prop_dict_keysym_alloc(const char *key)
_prop_dict_keysym_put(pdk); _prop_dict_keysym_put(pdk);
return (opdk); return (opdk);
} }
_prop_rb_tree_insert_node(&_prop_dict_keysym_tree, &pdk->pdk_link); rv = _prop_rb_tree_insert_node(&_prop_dict_keysym_tree, &pdk->pdk_link);
_PROP_ASSERT(rv == true);
_PROP_MUTEX_UNLOCK(_prop_dict_keysym_tree_mutex); _PROP_MUTEX_UNLOCK(_prop_dict_keysym_tree_mutex);
return (pdk); return (pdk);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: prop_number.c,v 1.17 2008/04/28 20:22:53 martin Exp $ */ /* $NetBSD: prop_number.c,v 1.18 2008/06/17 21:29:47 thorpej Exp $ */
/*- /*-
* Copyright (c) 2006 The NetBSD Foundation, Inc. * Copyright (c) 2006 The NetBSD Foundation, Inc.
@ -244,6 +244,7 @@ _prop_number_alloc(const struct _prop_number_value *pnv)
{ {
prop_number_t opn, pn; prop_number_t opn, pn;
struct rb_node *n; struct rb_node *n;
bool rv;
/* /*
* Check to see if this already exists in the tree. If it does, * Check to see if this already exists in the tree. If it does,
@ -290,7 +291,8 @@ _prop_number_alloc(const struct _prop_number_value *pnv)
_PROP_POOL_PUT(_prop_number_pool, pn); _PROP_POOL_PUT(_prop_number_pool, pn);
return (opn); return (opn);
} }
_prop_rb_tree_insert_node(&_prop_number_tree, &pn->pn_link); rv = _prop_rb_tree_insert_node(&_prop_number_tree, &pn->pn_link);
_PROP_ASSERT(rv == true);
_PROP_MUTEX_UNLOCK(_prop_number_tree_mutex); _PROP_MUTEX_UNLOCK(_prop_number_tree_mutex);
return (pn); return (pn);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: prop_rb.c,v 1.8 2008/04/28 20:22:53 martin Exp $ */ /* $NetBSD: prop_rb.c,v 1.9 2008/06/17 21:29:47 thorpej Exp $ */
/*- /*-
* Copyright (c) 2001 The NetBSD Foundation, Inc. * Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -151,7 +151,7 @@ rb_tree_reparent_nodes(struct rb_tree *rbt _PROP_ARG_UNUSED,
KASSERT(RB_ROOT_P(new_father) || rb_tree_check_node(rbt, grandpa, NULL, false)); KASSERT(RB_ROOT_P(new_father) || rb_tree_check_node(rbt, grandpa, NULL, false));
} }
void bool
_prop_rb_tree_insert_node(struct rb_tree *rbt, struct rb_node *self) _prop_rb_tree_insert_node(struct rb_tree *rbt, struct rb_node *self)
{ {
struct rb_node *parent, *tmp; struct rb_node *parent, *tmp;
@ -176,6 +176,12 @@ _prop_rb_tree_insert_node(struct rb_tree *rbt, struct rb_node *self)
*/ */
while (!RB_SENTINEL_P(tmp)) { while (!RB_SENTINEL_P(tmp)) {
const int diff = (*compare_nodes)(tmp, self); const int diff = (*compare_nodes)(tmp, self);
if (__predict_false(diff == 0)) {
/*
* Node already exists; don't insert.
*/
return false;
}
parent = tmp; parent = tmp;
KASSERT(diff != 0); KASSERT(diff != 0);
if (diff < 0) { if (diff < 0) {
@ -267,6 +273,8 @@ _prop_rb_tree_insert_node(struct rb_tree *rbt, struct rb_node *self)
*/ */
_prop_rb_tree_check(rbt, true); _prop_rb_tree_check(rbt, true);
#endif #endif
return true;
} }
static void static void

View File

@ -1,4 +1,4 @@
/* $NetBSD: prop_rb_impl.h,v 1.5 2008/04/28 20:22:53 martin Exp $ */ /* $NetBSD: prop_rb_impl.h,v 1.6 2008/06/17 21:29:47 thorpej Exp $ */
/*- /*-
* Copyright (c) 2001 The NetBSD Foundation, Inc. * Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -125,7 +125,7 @@ struct rb_tree {
}; };
void _prop_rb_tree_init(struct rb_tree *, const struct rb_tree_ops *); void _prop_rb_tree_init(struct rb_tree *, const struct rb_tree_ops *);
void _prop_rb_tree_insert_node(struct rb_tree *, struct rb_node *); bool _prop_rb_tree_insert_node(struct rb_tree *, struct rb_node *);
struct rb_node * struct rb_node *
_prop_rb_tree_find(struct rb_tree *, const void *); _prop_rb_tree_find(struct rb_tree *, const void *);
void _prop_rb_tree_remove_node(struct rb_tree *, struct rb_node *); void _prop_rb_tree_remove_node(struct rb_tree *, struct rb_node *);