[sr-dev] git:master:876c20cf: mem: added api structures for pkg and shm management

Daniel-Constantin Mierla miconda at gmail.com
Mon Sep 14 10:23:04 CEST 2015


Module: kamailio
Branch: master
Commit: 876c20cf55b23507dd390d177d5a7138d04815e4
URL: https://github.com/kamailio/kamailio/commit/876c20cf55b23507dd390d177d5a7138d04815e4

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2015-09-14T10:22:45+02:00

mem: added api structures for pkg and shm management

- a framework to allow specifying the memory manager at startup

---

Added: mem/memapi.h

---

Diff:  https://github.com/kamailio/kamailio/commit/876c20cf55b23507dd390d177d5a7138d04815e4.diff
Patch: https://github.com/kamailio/kamailio/commit/876c20cf55b23507dd390d177d5a7138d04815e4.patch

---

diff --git a/mem/memapi.h b/mem/memapi.h
new file mode 100644
index 0000000..e1b78a0
--- /dev/null
+++ b/mem/memapi.h
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2015 Daniel-Constantin Mierla (asipto.com)
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+
+#ifndef _sr_mem_api_
+#define _sr_mem_api_
+
+#include "src_loc.h"
+#include "meminfo.h"
+#include "memdbg.h"
+
+#ifdef DBG_SR_MEMORY
+
+typedef void* (*sr_malloc_f)(void* mbp, unsigned long size,
+					const char* file, const char* func, unsigned int line);
+typedef void  (*sr_free_f)(void* mbp, void* p, const char* file, const char* func, 
+					unsigned int line);
+typedef void* (*sr_realloc_f)(void* mbp, void* p, unsigned long size,
+					const char* file, const char* func, unsigned int line);
+typedef void* (*sr_resize_f)(void* mbp, void* p, unsigned long size,
+					const char* file, const char* func, unsigned int line);
+
+#else /*DBG_SR_MEMORY*/
+
+typedef void* (*sr_malloc_f)(void* mbp, unsigned long size);
+typedef void  (*sr_free_f)(void* mbp, void* p);
+typedef void* (*sr_realloc_f)(void* mbp, void* p, unsigned long size);
+typedef void* (*sr_resize_f)(void* mbp, void* p, unsigned long size);
+
+#endif /*DBG_SR_MEMORY*/
+
+typedef void  (*sr_mem_status_f)(void* mbp);
+typedef void  (*sr_mem_info_f)(void* mbp, struct mem_info* info);
+typedef unsigned long (*sr_mem_available_f)(void* mbp);
+typedef void  (*sr_mem_sums_f)(void* mbp);
+
+typedef void  (*sr_mem_destroy_f)(void);
+
+/*private memory api*/
+typedef struct sr_pkg_api {
+	/*memory manager name - soft copy*/
+	char *mname;
+	/*entire private memory zone - soft copy*/
+	char *mem_pool;
+	/*memory manager block - soft copy*/
+	void *mem_block;
+	/*memory chunk allocation*/
+	sr_malloc_f        xmalloc;
+	/*memory chunk reallocation*/
+	sr_realloc_f       xrealloc;
+	/*memory chunk free*/
+	sr_free_f          xfree;
+	/*memory status*/
+	sr_mem_status_f    xstatus;
+	/*memory info - internal metrics*/
+	sr_mem_info_f      xinfo;
+	/*memory available size*/
+	sr_mem_available_f xavailable;
+	/*memory summary*/
+	sr_mem_sums_f      xsums;
+	/*memory destroy manager*/
+	sr_mem_destroy_f   xdestroy;
+} sr_pkg_api_t;
+
+/*shared memory api*/
+typedef struct sr_shm_api {
+	/*memory manager name - soft copy*/
+	char *mname;
+	/*entire private memory zone - soft copy*/
+	void *mem_pool;
+	/*memory manager block - soft copy*/
+	void *mem_block;
+	/*memory chunk allocation*/
+	sr_malloc_f        xmalloc;
+	/*memory chunk allocation without locking shm*/
+	sr_malloc_f        xmalloc_unsafe;
+	/*memory chunk reallocation*/
+	sr_realloc_f       xrealloc;
+	/*memory chunk resizing - free+malloc in same locking*/
+	sr_resize_f        xresize;
+	/*memory chunk free*/
+	sr_free_f          xfree;
+	/*memory chunk free without locking shsm*/
+	sr_free_f          xfree_unsafe;
+	/*memory status*/
+	sr_mem_status_f    xstatus;
+	/*memory info - internal metrics*/
+	sr_mem_info_f      xinfo;
+	/*memory available size*/
+	sr_mem_available_f xavailable;
+	/*memory summary*/
+	sr_mem_sums_f      xsums;
+	/*memory destroy manager*/
+	sr_mem_destroy_f   xdestroy;
+} sr_shm_api_t;
+
+#endif




More information about the sr-dev mailing list