8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / fm / fmd / common / fmd_alloc.c
blob2c14dc9b30196ad60b219d53f6fcb73e9f858afb
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 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stdlib.h>
30 #include <strings.h>
31 #include <umem.h>
32 #include <poll.h>
33 #include <errno.h>
35 #include <fmd_alloc.h>
36 #include <fmd_subr.h>
37 #include <fmd_module.h>
38 #include <fmd_scheme.h>
39 #include <fmd.h>
41 void *
42 fmd_alloc(size_t size, int flags)
44 void *data = umem_alloc(size, UMEM_DEFAULT);
45 uint_t try, lim, msecs;
47 if (data != NULL || size == 0 || !(flags & FMD_SLEEP))
48 return (data); /* in common cases just return result */
50 lim = fmd.d_alloc_tries;
51 msecs = fmd.d_alloc_msecs;
53 for (try = 0; data == NULL && try < lim; try++) {
54 (void) poll(NULL, 0, msecs);
55 msecs *= 10;
56 data = umem_alloc(size, UMEM_DEFAULT);
59 if (data == NULL) {
60 fmd_modhash_tryapply(fmd.d_mod_hash, fmd_module_trygc);
61 fmd_scheme_hash_trygc(fmd.d_schemes);
62 data = umem_alloc(size, UMEM_DEFAULT);
65 if (data == NULL)
66 fmd_panic("insufficient memory (%u bytes needed)\n", size);
68 return (data);
71 void *
72 fmd_zalloc(size_t size, int flags)
74 void *data = fmd_alloc(size, flags);
76 if (data != NULL)
77 bzero(data, size);
79 return (data);
82 void
83 fmd_free(void *data, size_t size)
85 umem_free(data, size);