コード例 #1
0
ファイル: uu_avl.c プロジェクト: CTSRD-CHERI/cheribsd
void
uu_avl_destroy(uu_avl_t *ap)
{
	uu_avl_pool_t *pp = ap->ua_pool;

	if (ap->ua_debug) {
		if (avl_numnodes(&ap->ua_tree) != 0) {
			uu_panic("uu_avl_destroy(%p): tree not empty\n",
			    (void *)ap);
		}
		if (ap->ua_null_walk.uaw_next != &ap->ua_null_walk ||
		    ap->ua_null_walk.uaw_prev != &ap->ua_null_walk) {
			uu_panic("uu_avl_destroy(%p):  outstanding walkers\n",
			    (void *)ap);
		}
	}
	(void) pthread_mutex_lock(&pp->uap_lock);
	UU_AVL_PTR(ap->ua_next_enc)->ua_prev_enc = ap->ua_prev_enc;
	UU_AVL_PTR(ap->ua_prev_enc)->ua_next_enc = ap->ua_next_enc;
	(void) pthread_mutex_unlock(&pp->uap_lock);
	ap->ua_prev_enc = UU_PTR_ENCODE(NULL);
	ap->ua_next_enc = UU_PTR_ENCODE(NULL);

	ap->ua_pool = NULL;
	avl_destroy(&ap->ua_tree);

	uu_free(ap);
}
コード例 #2
0
ファイル: uu_list.c プロジェクト: mikess/illumos-gate
void
uu_list_destroy(uu_list_t *lp)
{
    uu_list_pool_t *pp = lp->ul_pool;

    if (lp->ul_debug) {
        if (lp->ul_null_node.uln_next != &lp->ul_null_node ||
                lp->ul_null_node.uln_prev != &lp->ul_null_node) {
            uu_panic("uu_list_destroy(%p):  list not empty\n",
                     (void *)lp);
        }
        if (lp->ul_numnodes != 0) {
            uu_panic("uu_list_destroy(%p):  numnodes is nonzero, "
                     "but list is empty\n", (void *)lp);
        }
        if (lp->ul_null_walk.ulw_next != &lp->ul_null_walk ||
                lp->ul_null_walk.ulw_prev != &lp->ul_null_walk) {
            uu_panic("uu_list_destroy(%p):  outstanding walkers\n",
                     (void *)lp);
        }
    }

    (void) pthread_mutex_lock(&pp->ulp_lock);
    UU_LIST_PTR(lp->ul_next_enc)->ul_prev_enc = lp->ul_prev_enc;
    UU_LIST_PTR(lp->ul_prev_enc)->ul_next_enc = lp->ul_next_enc;
    (void) pthread_mutex_unlock(&pp->ulp_lock);
    lp->ul_prev_enc = UU_PTR_ENCODE(NULL);
    lp->ul_next_enc = UU_PTR_ENCODE(NULL);
    lp->ul_pool = NULL;
    uu_free(lp);
}
コード例 #3
0
ファイル: uu_list.c プロジェクト: mikess/illumos-gate
uu_list_t *
uu_list_create(uu_list_pool_t *pp, void *parent, uint32_t flags)
{
    uu_list_t *lp, *next, *prev;

    if (flags & ~(UU_LIST_DEBUG | UU_LIST_SORTED)) {
        uu_set_error(UU_ERROR_UNKNOWN_FLAG);
        return (NULL);
    }

    if ((flags & UU_LIST_SORTED) && pp->ulp_cmp == NULL) {
        if (pp->ulp_debug)
            uu_panic("uu_list_create(%p, ...): requested "
                     "UU_LIST_SORTED, but pool has no comparison func\n",
                     (void *)pp);
        uu_set_error(UU_ERROR_NOT_SUPPORTED);
        return (NULL);
    }

    lp = uu_zalloc(sizeof (*lp));
    if (lp == NULL) {
        uu_set_error(UU_ERROR_NO_MEMORY);
        return (NULL);
    }

    lp->ul_pool = pp;
    lp->ul_parent_enc = UU_PTR_ENCODE(parent);
    lp->ul_offset = pp->ulp_nodeoffset;
    lp->ul_debug = pp->ulp_debug || (flags & UU_LIST_DEBUG);
    lp->ul_sorted = (flags & UU_LIST_SORTED);
    lp->ul_numnodes = 0;
    lp->ul_index = (pp->ulp_last_index = INDEX_NEXT(pp->ulp_last_index));

    lp->ul_null_node.uln_next = &lp->ul_null_node;
    lp->ul_null_node.uln_prev = &lp->ul_null_node;

    lp->ul_null_walk.ulw_next = &lp->ul_null_walk;
    lp->ul_null_walk.ulw_prev = &lp->ul_null_walk;

    (void) pthread_mutex_lock(&pp->ulp_lock);
    next = &pp->ulp_null_list;
    prev = UU_PTR_DECODE(next->ul_prev_enc);
    lp->ul_next_enc = UU_PTR_ENCODE(next);
    lp->ul_prev_enc = UU_PTR_ENCODE(prev);
    next->ul_prev_enc = UU_PTR_ENCODE(lp);
    prev->ul_next_enc = UU_PTR_ENCODE(lp);
    (void) pthread_mutex_unlock(&pp->ulp_lock);

    return (lp);
}
コード例 #4
0
ファイル: uu_avl.c プロジェクト: CTSRD-CHERI/cheribsd
uu_avl_pool_t *
uu_avl_pool_create(const char *name, size_t objsize, size_t nodeoffset,
    uu_compare_fn_t *compare_func, uint32_t flags)
{
	uu_avl_pool_t *pp, *next, *prev;

	if (name == NULL ||
	    uu_check_name(name, UU_NAME_DOMAIN) == -1 ||
	    nodeoffset + sizeof (uu_avl_node_t) > objsize ||
	    compare_func == NULL) {
		uu_set_error(UU_ERROR_INVALID_ARGUMENT);
		return (NULL);
	}

	if (flags & ~UU_AVL_POOL_DEBUG) {
		uu_set_error(UU_ERROR_UNKNOWN_FLAG);
		return (NULL);
	}

	pp = uu_zalloc(sizeof (uu_avl_pool_t));
	if (pp == NULL) {
		uu_set_error(UU_ERROR_NO_MEMORY);
		return (NULL);
	}

	(void) strlcpy(pp->uap_name, name, sizeof (pp->uap_name));
	pp->uap_nodeoffset = nodeoffset;
	pp->uap_objsize = objsize;
	pp->uap_cmp = compare_func;
	if (flags & UU_AVL_POOL_DEBUG)
		pp->uap_debug = 1;
	pp->uap_last_index = 0;

	(void) pthread_mutex_init(&pp->uap_lock, NULL);

	pp->uap_null_avl.ua_next_enc = UU_PTR_ENCODE(&pp->uap_null_avl);
	pp->uap_null_avl.ua_prev_enc = UU_PTR_ENCODE(&pp->uap_null_avl);

	(void) pthread_mutex_lock(&uu_apool_list_lock);
	pp->uap_next = next = &uu_null_apool;
	pp->uap_prev = prev = next->uap_prev;
	next->uap_prev = pp;
	prev->uap_next = pp;
	(void) pthread_mutex_unlock(&uu_apool_list_lock);

	return (pp);
}
コード例 #5
0
ファイル: uu_list.c プロジェクト: andreiw/polaris
void
uu_list_pool_destroy(uu_list_pool_t *pp)
{
	if (pp->ulp_debug) {
		if (pp->ulp_null_list.ul_next_enc !=
		    UU_PTR_ENCODE(&pp->ulp_null_list) ||
		    pp->ulp_null_list.ul_prev_enc !=
		    UU_PTR_ENCODE(&pp->ulp_null_list)) {
			uu_panic("uu_list_pool_destroy: Pool \"%.*s\" (%p) has "
			    "outstanding lists, or is corrupt.\n",
			    sizeof (pp->ulp_name), pp->ulp_name, pp);
		}
	}
	(void) pthread_mutex_lock(&uu_lpool_list_lock);
	pp->ulp_next->ulp_prev = pp->ulp_prev;
	pp->ulp_prev->ulp_next = pp->ulp_next;
	(void) pthread_mutex_unlock(&uu_lpool_list_lock);
	pp->ulp_prev = NULL;
	pp->ulp_next = NULL;
	uu_free(pp);
}
コード例 #6
0
ファイル: uu_avl.c プロジェクト: 151706061/osv
void
uu_avl_pool_destroy(uu_avl_pool_t *pp)
{
	if (pp->uap_debug) {
		if (pp->uap_null_avl.ua_next_enc !=
		    UU_PTR_ENCODE(&pp->uap_null_avl) ||
		    pp->uap_null_avl.ua_prev_enc !=
		    UU_PTR_ENCODE(&pp->uap_null_avl)) {
			uu_panic("uu_avl_pool_destroy: Pool \"%.*s\" (%p) has "
			    "outstanding avls, or is corrupt.\n",
			    (int)sizeof (pp->uap_name), pp->uap_name,
			    (void *)pp);
		}
	}
	(void) pthread_mutex_lock(&uu_apool_list_lock);
	pp->uap_next->uap_prev = pp->uap_prev;
	pp->uap_prev->uap_next = pp->uap_next;
	(void) pthread_mutex_unlock(&uu_apool_list_lock);
	pp->uap_prev = NULL;
	pp->uap_next = NULL;
	uu_free(pp);
}
コード例 #7
0
ファイル: uu_avl.c プロジェクト: CTSRD-CHERI/cheribsd
uu_avl_t *
uu_avl_create(uu_avl_pool_t *pp, void *parent, uint32_t flags)
{
	uu_avl_t *ap, *next, *prev;

	if (flags & ~UU_AVL_DEBUG) {
		uu_set_error(UU_ERROR_UNKNOWN_FLAG);
		return (NULL);
	}

	ap = uu_zalloc(sizeof (*ap));
	if (ap == NULL) {
		uu_set_error(UU_ERROR_NO_MEMORY);
		return (NULL);
	}

	ap->ua_pool = pp;
	ap->ua_parent_enc = UU_PTR_ENCODE(parent);
	ap->ua_debug = pp->uap_debug || (flags & UU_AVL_DEBUG);
	ap->ua_index = (pp->uap_last_index = INDEX_NEXT(pp->uap_last_index));

	avl_create(&ap->ua_tree, &uu_avl_node_compare, pp->uap_objsize,
	    pp->uap_nodeoffset);

	ap->ua_null_walk.uaw_next = &ap->ua_null_walk;
	ap->ua_null_walk.uaw_prev = &ap->ua_null_walk;

	(void) pthread_mutex_lock(&pp->uap_lock);
	next = &pp->uap_null_avl;
	prev = UU_PTR_DECODE(next->ua_prev_enc);
	ap->ua_next_enc = UU_PTR_ENCODE(next);
	ap->ua_prev_enc = UU_PTR_ENCODE(prev);
	next->ua_prev_enc = UU_PTR_ENCODE(ap);
	prev->ua_next_enc = UU_PTR_ENCODE(ap);
	(void) pthread_mutex_unlock(&pp->uap_lock);

	return (ap);
}