8158 Want named threads API
[unleashed.git] / usr / src / cmd / mdb / common / mdb / mdb_addrvec.c
blob052aa3d0d652612e38a9fc7e306a17109fd77871
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <mdb/mdb_addrvec.h>
30 #include <mdb/mdb_debug.h>
31 #include <mdb/mdb_modapi.h>
33 #include <strings.h>
35 #define AD_INIT 16 /* initial size of addrvec array */
36 #define AD_GROW 2 /* array growth multiplier */
38 void
39 mdb_addrvec_create(mdb_addrvec_t *adp)
41 bzero(adp, sizeof (mdb_addrvec_t));
44 void
45 mdb_addrvec_destroy(mdb_addrvec_t *adp)
47 mdb_free(adp->ad_data, sizeof (uintptr_t) * adp->ad_size);
48 bzero(adp, sizeof (mdb_addrvec_t));
51 void
52 mdb_addrvec_unshift(mdb_addrvec_t *adp, uintptr_t value)
54 if (adp->ad_nelems >= adp->ad_size) {
55 size_t size = adp->ad_size ? adp->ad_size * AD_GROW : AD_INIT;
56 void *data = mdb_alloc(sizeof (uintptr_t) * size, UM_SLEEP);
58 bcopy(adp->ad_data, data, sizeof (uintptr_t) * adp->ad_size);
59 mdb_free(adp->ad_data, sizeof (uintptr_t) * adp->ad_size);
61 adp->ad_data = data;
62 adp->ad_size = size;
65 adp->ad_data[adp->ad_nelems++] = value;
68 uintptr_t
69 mdb_addrvec_shift(mdb_addrvec_t *adp)
71 if (adp->ad_ndx < adp->ad_nelems)
72 return (adp->ad_data[adp->ad_ndx++]);
74 return ((uintptr_t)-1L);
77 size_t
78 mdb_addrvec_length(mdb_addrvec_t *adp)
80 if (adp != NULL) {
81 ASSERT(adp->ad_nelems >= adp->ad_ndx);
82 return (adp->ad_nelems - adp->ad_ndx);
85 return (0); /* convenience for callers */