root / Whitix / branches / network / include / slab.h

Revision 1, 1.9 kB (checked in by mtw07, 11 months ago)

Initial import of projects.

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 <llist.h>
25#include <types.h>
26
27#define SLAB_SIZE PAGE_SIZE
28#define SLAB_MIN_OBJECT_SIZE 16
29/* Max objects is needed when allocating a bitmap of free objects in a slab */
30#define MAX_OBJECTS_PER_SLAB (SLAB_SIZE/SLAB_MIN_OBJECT_SIZE)
31
32/* Slab options */
33#define SLAB_OFFSLAB 1 /* Store the slab info off-slab */
34
35struct Slab
36{
37        DWORD page; /* Virtual address */
38        struct ListHead list;
39        BYTE isFull;
40        BYTE bitmap[MAX_OBJECTS_PER_SLAB/8];
41};
42
43typedef void (*Constructor)(void* obj);
44typedef void (*Destructor)(void* obj);
45
46struct Cache
47{
48        struct ListHead list;
49        Constructor ctor;
50        Destructor dtor;
51        const char* name;
52        int options,numObjs,offset;
53        size_t size;
54        struct Slab* slabs; /* Each cache owns a number of slabs */
55        int numPages; /* per slab */
56};
57
58struct Cache* MemCacheCreate(const char* name,size_t size,Constructor ctor,Destructor dtor,int options);
59void* MemCacheAlloc(struct Cache* cache);
60int MemCacheFree(struct Cache* cache,void* obj);
61int MemCacheDestroy(struct Cache* cache);
62
63#endif
Note: See TracBrowser for help on using the browser.