Browse code

mem: added api structures for pkg and shm management

- a framework to allow specifying the memory manager at startup

Daniel-Constantin Mierla authored on 14/09/2015 07:18:59
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,112 @@
1
+/*
2
+ * Copyright (C) 2015 Daniel-Constantin Mierla (asipto.com)
3
+ *
4
+ * This file is part of Kamailio, a free SIP server.
5
+ *
6
+ * Permission to use, copy, modify, and distribute this software for any
7
+ * purpose with or without fee is hereby granted, provided that the above
8
+ * copyright notice and this permission notice appear in all copies.
9
+ *
10
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
+ */
18
+
19
+
20
+#ifndef _sr_mem_api_
21
+#define _sr_mem_api_
22
+
23
+#include "src_loc.h"
24
+#include "meminfo.h"
25
+#include "memdbg.h"
26
+
27
+#ifdef DBG_SR_MEMORY
28
+
29
+typedef void* (*sr_malloc_f)(void* mbp, unsigned long size,
30
+					const char* file, const char* func, unsigned int line);
31
+typedef void  (*sr_free_f)(void* mbp, void* p, const char* file, const char* func, 
32
+					unsigned int line);
33
+typedef void* (*sr_realloc_f)(void* mbp, void* p, unsigned long size,
34
+					const char* file, const char* func, unsigned int line);
35
+typedef void* (*sr_resize_f)(void* mbp, void* p, unsigned long size,
36
+					const char* file, const char* func, unsigned int line);
37
+
38
+#else /*DBG_SR_MEMORY*/
39
+
40
+typedef void* (*sr_malloc_f)(void* mbp, unsigned long size);
41
+typedef void  (*sr_free_f)(void* mbp, void* p);
42
+typedef void* (*sr_realloc_f)(void* mbp, void* p, unsigned long size);
43
+typedef void* (*sr_resize_f)(void* mbp, void* p, unsigned long size);
44
+
45
+#endif /*DBG_SR_MEMORY*/
46
+
47
+typedef void  (*sr_mem_status_f)(void* mbp);
48
+typedef void  (*sr_mem_info_f)(void* mbp, struct mem_info* info);
49
+typedef unsigned long (*sr_mem_available_f)(void* mbp);
50
+typedef void  (*sr_mem_sums_f)(void* mbp);
51
+
52
+typedef void  (*sr_mem_destroy_f)(void);
53
+
54
+/*private memory api*/
55
+typedef struct sr_pkg_api {
56
+	/*memory manager name - soft copy*/
57
+	char *mname;
58
+	/*entire private memory zone - soft copy*/
59
+	char *mem_pool;
60
+	/*memory manager block - soft copy*/
61
+	void *mem_block;
62
+	/*memory chunk allocation*/
63
+	sr_malloc_f        xmalloc;
64
+	/*memory chunk reallocation*/
65
+	sr_realloc_f       xrealloc;
66
+	/*memory chunk free*/
67
+	sr_free_f          xfree;
68
+	/*memory status*/
69
+	sr_mem_status_f    xstatus;
70
+	/*memory info - internal metrics*/
71
+	sr_mem_info_f      xinfo;
72
+	/*memory available size*/
73
+	sr_mem_available_f xavailable;
74
+	/*memory summary*/
75
+	sr_mem_sums_f      xsums;
76
+	/*memory destroy manager*/
77
+	sr_mem_destroy_f   xdestroy;
78
+} sr_pkg_api_t;
79
+
80
+/*shared memory api*/
81
+typedef struct sr_shm_api {
82
+	/*memory manager name - soft copy*/
83
+	char *mname;
84
+	/*entire private memory zone - soft copy*/
85
+	void *mem_pool;
86
+	/*memory manager block - soft copy*/
87
+	void *mem_block;
88
+	/*memory chunk allocation*/
89
+	sr_malloc_f        xmalloc;
90
+	/*memory chunk allocation without locking shm*/
91
+	sr_malloc_f        xmalloc_unsafe;
92
+	/*memory chunk reallocation*/
93
+	sr_realloc_f       xrealloc;
94
+	/*memory chunk resizing - free+malloc in same locking*/
95
+	sr_resize_f        xresize;
96
+	/*memory chunk free*/
97
+	sr_free_f          xfree;
98
+	/*memory chunk free without locking shsm*/
99
+	sr_free_f          xfree_unsafe;
100
+	/*memory status*/
101
+	sr_mem_status_f    xstatus;
102
+	/*memory info - internal metrics*/
103
+	sr_mem_info_f      xinfo;
104
+	/*memory available size*/
105
+	sr_mem_available_f xavailable;
106
+	/*memory summary*/
107
+	sr_mem_sums_f      xsums;
108
+	/*memory destroy manager*/
109
+	sr_mem_destroy_f   xdestroy;
110
+} sr_shm_api_t;
111
+
112
+#endif