Add MPF_INT (for mpipe_init()), which allows one to specify that an MPIPE
[dragonfly.git] / sys / sys / mpipe.h
1 /*
2  * Copyright (c) 2003 Matthew Dillon <dillon@backplane.com>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $DragonFly: src/sys/sys/mpipe.h,v 1.3 2004/06/04 06:56:11 dillon Exp $
27  */
28
29 #ifndef _SYS_MPIPE_H_
30 #define _SYS_MPIPE_H_
31
32 #ifndef _SYS_MALLOC_H_
33 #include <sys/malloc.h>
34 #endif
35
36 /*
37  * Pipeline memory allocations with persistent store capabilities.  This
38  * implements a pipeline for allocations of a particular size.  It is used
39  * in order to allow memory allocations to block while at the same time
40  * guarenteeing that no deadlocks will occur.
41  *
42  * By default new allocations are zero'd out. 
43  *
44  * MPF_NOZERO           If specified the underlying buffers are not zero'd.
45  *                      Note this also means you have no way of knowing which
46  *                      buffers are coming from the cache and which are new
47  *                      allocations.
48  *
49  * MPF_CACHEDATA        If specified the deconstructor will be called when
50  *                      the underlying buffer is free()'d, but the buffer may
51  *                      be reused many times before/if that happens.  The
52  *                      buffer is NOT zero'd on reuse regardless of the
53  *                      MPF_NOZERO flag.
54  *
55  *                      If not specified and MPF_NOZERO is also not specified,
56  *                      then buffers reused from the cache will be zero'd as
57  *                      well as new allocations.
58  *
59  *                      Note that the deconstructor function may still be NULL
60  *                      if this flag is specified, meaning that you don't need
61  *                      notification when the cached contents is physically
62  *                      free()'d.
63  *
64  * MPF_INT              Use the interrupt reserve if necessary.
65  */
66 struct mpipe_buf;
67
68 struct malloc_pipe {
69     malloc_type_t type;         /* malloc bucket */
70     int         bytes;          /* allocation size */
71     int         mpflags;        /* MPF_ flags */
72     int         mflags;         /* M_ flags (used internally) */
73     int         pending;        /* there is a request pending */
74     int         free_count;     /* entries in array[] */
75     int         total_count;    /* total outstanding allocations incl free */
76     int         ary_count;      /* guarenteed allocation count */
77     int         max_count;      /* maximum count (M_NOWAIT used beyond nom) */
78     void        **array;        /* array[ary_count] */
79     void        (*deconstruct)(struct malloc_pipe *, void *buf);
80 };
81
82 #define MPF_CACHEDATA           0x0001  /* cache old buffers (do not zero) */ 
83 #define MPF_NOZERO              0x0002  /* do not zero-out new allocations */
84 #define MPF_INT                 0x0004  /* use the interrupt memory reserve */
85
86 typedef struct malloc_pipe *malloc_pipe_t;
87
88 #ifdef _KERNEL
89
90 void mpipe_init(malloc_pipe_t mpipe, malloc_type_t type,
91                 int bytes, int nnom, int nmax, 
92                 int mpflags, void (*deconstruct)(struct malloc_pipe *, void *));
93 void mpipe_done(malloc_pipe_t mpipe);
94 void *mpipe_alloc_waitok(malloc_pipe_t mpipe);
95 void *mpipe_alloc_nowait(malloc_pipe_t mpipe);
96 void mpipe_free(malloc_pipe_t mpipe, void *vbuf);
97
98 #endif
99
100 #endif
101