root/Whitix/trunk/include/slab.h

Revision 1668, 1.9 KB (checked in by mwhitworth, 3 years ago)

Merge in changes from keobject.

Line 
1/*  This file is part of Whitix.
2 *
3 *  Whitix is free software; you can redistribute it and/or modify
4 *  it under the terms of the GNU General Public License as published by
5 *  the Free Software Foundation; either version 2 of the License, or
6 *  (at your option) any later version.
7 *
8 *  Whitix is distributed in the hope that it will be useful,
9 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *  GNU General Public License for more details.
12 *
13 *  You should have received a copy of the GNU General Public License
14 *  along with Whitix; if not, write to the Free Software
15 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16 *
17 */
18
19#ifndef SLAB_H
20#define SLAB_H
21
22#include <i386/virtual.h>
23#include <typedefs.h>
24#include <keobject.h>
25#include <llist.h>
26#include <types.h>
27
28#define SLAB_SIZE PAGE_SIZE
29#define SLAB_MIN_OBJECT_SIZE 16
30/* Max objects is needed when allocating a bitmap of free objects in a slab */
31#define MAX_OBJECTS_PER_SLAB (SLAB_SIZE/SLAB_MIN_OBJECT_SIZE)
32
33/* Slab options */
34#define SLAB_OFFSLAB 1 /* Store the slab info off-slab */
35
36#define MALLOC_MAX_SIZE         131072
37
38struct Slab
39{
40        DWORD page; /* Virtual address */
41        struct ListHead list;
42        BYTE isFull;
43        BYTE bitmap[MAX_OBJECTS_PER_SLAB/8];
44};
45
46typedef void (*Constructor)(void* obj);
47typedef void (*Destructor)(void* obj);
48
49struct Cache
50{
51        struct ListHead list;
52        Constructor ctor;
53        Destructor dtor;
54        struct KeObject object;
55        const char* name;
56        int options, numObjs, offset;
57        size_t size;
58        struct Slab* slabs; /* Each cache owns a number of slabs */
59        int numPages; /* per slab */
60};
61
62struct Cache* MemCacheCreate(const char* name,size_t size,Constructor ctor,Destructor dtor,int options);
63void* MemCacheAlloc(struct Cache* cache);
64int MemCacheFree(struct Cache* cache,void* obj);
65int MemCacheDestroy(struct Cache* cache);
66
67#endif
Note: See TracBrowser for help on using the browser.