-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory_cache.h
executable file
·53 lines (42 loc) · 1.11 KB
/
memory_cache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// Created by root on 18-7-23.
//
#ifndef TEST_QOS_MEMORY_CACHE_H
#define TEST_QOS_MEMORY_CACHE_H
#include <sys/param.h>
#ifdef __cplusplus
extern "C" {
#endif
#define MEMORY_CACHE_TEST
#define CACHE_OPEN_CNT
#ifdef MEMORY_CACHE_TEST
#ifndef CACHE_OPEN_CNT
#define CACHE_OPEN_CNT
#endif
#endif
//FIXME: 此类暂时之提供接口不提供 实际的与分配缓存
typedef struct memory_cache
{
unsigned long unit_size;
unsigned long cache_unit;
/**************************************************/
void *(*alloc)(struct memory_cache *cache);
void (*free)(struct memory_cache *cache, void *data);
/**************************************************/
#ifdef CACHE_OPEN_CNT
unsigned long alloc_cnt;
unsigned long free_cnt;
pthread_spinlock_t lck;
#endif
} memory_cache_t;
int memory_cache_init(memory_cache_t *cache, unsigned long unit_size,
unsigned long cache_unit);
void memory_cache_exit(memory_cache_t *cache);
#ifdef MEMORY_CACHE_TEST
//测试接口
void test_memory_cache();
#endif
#ifdef __cplusplus
}
#endif
#endif //TEST_QOS_MEMORY_CACHE_H