|
Revision 1668, 1.9 KB
(checked in by mwhitworth, 3 years ago)
|
|
Merge in changes from keobject.
|
| Line | |
|---|
| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 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 | |
|---|
| 31 | #define MAX_OBJECTS_PER_SLAB (SLAB_SIZE/SLAB_MIN_OBJECT_SIZE) |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | #define SLAB_OFFSLAB 1 |
|---|
| 35 | |
|---|
| 36 | #define MALLOC_MAX_SIZE 131072 |
|---|
| 37 | |
|---|
| 38 | struct Slab |
|---|
| 39 | { |
|---|
| 40 | DWORD page; |
|---|
| 41 | struct ListHead list; |
|---|
| 42 | BYTE isFull; |
|---|
| 43 | BYTE bitmap[MAX_OBJECTS_PER_SLAB/8]; |
|---|
| 44 | }; |
|---|
| 45 | |
|---|
| 46 | typedef void (*Constructor)(void* obj); |
|---|
| 47 | typedef void (*Destructor)(void* obj); |
|---|
| 48 | |
|---|
| 49 | struct 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; |
|---|
| 59 | int numPages; |
|---|
| 60 | }; |
|---|
| 61 | |
|---|
| 62 | struct Cache* MemCacheCreate(const char* name,size_t size,Constructor ctor,Destructor dtor,int options); |
|---|
| 63 | void* MemCacheAlloc(struct Cache* cache); |
|---|
| 64 | int MemCacheFree(struct Cache* cache,void* obj); |
|---|
| 65 | int MemCacheDestroy(struct Cache* cache); |
|---|
| 66 | |
|---|
| 67 | #endif |
|---|