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