Tenok
A Linux-like Real-Time Operating System for Robotics and Internet of Things
slab.h
Go to the documentation of this file.
1 
4 #ifndef __SLAB_H__
5 #define __SLAB_H__
6 
7 #include <common/list.h>
8 
9 #define CACHE_PAGE_SIZE 256
10 #define CACHE_NAME_LEN 16
11 
12 #define CACHE_OPT_NONE 0
13 
14 struct kmem_cache {
15  struct list_head slabs_free;
16  struct list_head slabs_partial;
17  struct list_head slabs_full;
18  struct list_head list;
19  unsigned short objsize;
20  unsigned short objnum;
21  unsigned short page_order;
22  int opts;
23  int alloc_succeed;
24  int alloc_fail;
25  char name[CACHE_NAME_LEN];
26 };
27 
28 struct slab {
29  unsigned long free_bitmap[1];
30  int free_objects;
31  struct list_head list;
32  char data[0];
33 };
34 
44 struct kmem_cache *kmem_cache_create(const char *name,
45  size_t size,
46  size_t align,
47  unsigned long flags,
48  void (*ctor)(void *));
49 
56 void *kmem_cache_alloc(struct kmem_cache *cache, unsigned long flags);
57 
64 void kmem_cache_free(struct kmem_cache *cache, void *obj);
65 
66 void kmem_cache_init(void);
67 
68 #endif
void kmem_cache_free(struct kmem_cache *cache, void *obj)
Free the allocated slab memory.
Definition: slab.c:165
void * kmem_cache_alloc(struct kmem_cache *cache, unsigned long flags)
Allocate a new slab memory.
Definition: slab.c:106
struct kmem_cache * kmem_cache_create(const char *name, size_t size, size_t align, unsigned long flags, void(*ctor)(void *))
Create a new slab cache.
Definition: slab.c:42
Definition: slab.h:14
Definition: list.h:111
Definition: slab.h:28