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