xref: /netbsd-src/external/cddl/osnet/include/umem.h (revision fc8ec0b896620494ee06c82427885881da50d528)
1*fc8ec0b8Shaad /*	$NetBSD: umem.h,v 1.1 2009/08/07 20:57:55 haad Exp $	*/
2*fc8ec0b8Shaad 
3*fc8ec0b8Shaad /*
4*fc8ec0b8Shaad  * CDDL HEADER START
5*fc8ec0b8Shaad  *
6*fc8ec0b8Shaad  * The contents of this file are subject to the terms of the
7*fc8ec0b8Shaad  * Common Development and Distribution License, Version 1.0 only
8*fc8ec0b8Shaad  * (the "License").  You may not use this file except in compliance
9*fc8ec0b8Shaad  * with the License.
10*fc8ec0b8Shaad  *
11*fc8ec0b8Shaad  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
12*fc8ec0b8Shaad  * or http://www.opensolaris.org/os/licensing.
13*fc8ec0b8Shaad  * See the License for the specific language governing permissions
14*fc8ec0b8Shaad  * and limitations under the License.
15*fc8ec0b8Shaad  *
16*fc8ec0b8Shaad  * When distributing Covered Code, include this CDDL HEADER in each
17*fc8ec0b8Shaad  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
18*fc8ec0b8Shaad  * If applicable, add the following below this CDDL HEADER, with the
19*fc8ec0b8Shaad  * fields enclosed by brackets "[]" replaced with your own identifying
20*fc8ec0b8Shaad  * information: Portions Copyright [yyyy] [name of copyright owner]
21*fc8ec0b8Shaad  *
22*fc8ec0b8Shaad  * CDDL HEADER END
23*fc8ec0b8Shaad  */
24*fc8ec0b8Shaad /*
25*fc8ec0b8Shaad  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
26*fc8ec0b8Shaad  * Use is subject to license terms.
27*fc8ec0b8Shaad  */
28*fc8ec0b8Shaad 
29*fc8ec0b8Shaad #ifndef _UMEM_H
30*fc8ec0b8Shaad #define	_UMEM_H
31*fc8ec0b8Shaad 
32*fc8ec0b8Shaad 
33*fc8ec0b8Shaad 
34*fc8ec0b8Shaad #include <sys/types.h>
35*fc8ec0b8Shaad #include <stdlib.h>
36*fc8ec0b8Shaad 
37*fc8ec0b8Shaad #ifdef	__cplusplus
38*fc8ec0b8Shaad extern "C" {
39*fc8ec0b8Shaad #endif
40*fc8ec0b8Shaad 
41*fc8ec0b8Shaad #define	UMEM_DEFAULT	0x0000	/* normal -- may fail */
42*fc8ec0b8Shaad #define	UMEM_NOFAIL	0x0100	/* Never fails -- may call exit(2) */
43*fc8ec0b8Shaad 
44*fc8ec0b8Shaad #define	UMEM_FLAGS	0xffff	/* all settable umem flags */
45*fc8ec0b8Shaad 
46*fc8ec0b8Shaad extern void *umem_alloc(size_t, int);
47*fc8ec0b8Shaad extern void *umem_alloc_align(size_t, size_t, int);
48*fc8ec0b8Shaad extern void *umem_zalloc(size_t, int);
49*fc8ec0b8Shaad extern void umem_free(void *, size_t);
50*fc8ec0b8Shaad extern void umem_free_align(void *, size_t);
51*fc8ec0b8Shaad 
52*fc8ec0b8Shaad /*
53*fc8ec0b8Shaad  * Flags for umem_cache_create()
54*fc8ec0b8Shaad  */
55*fc8ec0b8Shaad #define	UMC_NOTOUCH	0x00010000
56*fc8ec0b8Shaad #define	UMC_NODEBUG	0x00020000
57*fc8ec0b8Shaad #define	UMC_NOMAGAZINE	0x00040000
58*fc8ec0b8Shaad #define	UMC_NOHASH	0x00080000
59*fc8ec0b8Shaad 
60*fc8ec0b8Shaad struct umem_cache;		/* cache structure is opaque to umem clients */
61*fc8ec0b8Shaad 
62*fc8ec0b8Shaad typedef struct umem_cache umem_cache_t;
63*fc8ec0b8Shaad typedef int umem_constructor_t(void *, void *, int);
64*fc8ec0b8Shaad typedef void umem_destructor_t(void *, void *);
65*fc8ec0b8Shaad typedef void umem_reclaim_t(void *);
66*fc8ec0b8Shaad 
67*fc8ec0b8Shaad typedef int umem_nofail_callback_t(void);
68*fc8ec0b8Shaad #define	UMEM_CALLBACK_RETRY		0
69*fc8ec0b8Shaad #define	UMEM_CALLBACK_EXIT(status)	(0x100 | ((status) & 0xFF))
70*fc8ec0b8Shaad 
71*fc8ec0b8Shaad extern void umem_nofail_callback(umem_nofail_callback_t *);
72*fc8ec0b8Shaad 
73*fc8ec0b8Shaad extern umem_cache_t *umem_cache_create(char *, size_t,
74*fc8ec0b8Shaad     size_t, umem_constructor_t *, umem_destructor_t *, umem_reclaim_t *,
75*fc8ec0b8Shaad     void *, void *, int);
76*fc8ec0b8Shaad extern void umem_cache_destroy(umem_cache_t *);
77*fc8ec0b8Shaad 
78*fc8ec0b8Shaad extern void *umem_cache_alloc(umem_cache_t *, int);
79*fc8ec0b8Shaad extern void umem_cache_free(umem_cache_t *, void *);
80*fc8ec0b8Shaad 
81*fc8ec0b8Shaad extern void umem_reap(void);
82*fc8ec0b8Shaad 
83*fc8ec0b8Shaad #ifdef	__cplusplus
84*fc8ec0b8Shaad }
85*fc8ec0b8Shaad #endif
86*fc8ec0b8Shaad 
87*fc8ec0b8Shaad #endif	/* _UMEM_H */
88