[API-NEXT,PATCHv8,3/6] linux-gen: drv: shm: adding pool allocator

Message ID 1484677083-12831-4-git-send-email-christophe.milard@linaro.org
State New
Headers show
Series
  • small memory amount allocator for drv shm
Related show

Commit Message

Christophe Milard Jan. 17, 2017, 6:18 p.m.
Adding functions to create memory pools and allocate / free memory from
the created pools.
These functions calls their _ishm conterpart, of course.

Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

---
 platform/linux-generic/drv_shm.c | 44 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

-- 
2.7.4

Patch

diff --git a/platform/linux-generic/drv_shm.c b/platform/linux-generic/drv_shm.c
index 9b2560d..325632e 100644
--- a/platform/linux-generic/drv_shm.c
+++ b/platform/linux-generic/drv_shm.c
@@ -8,6 +8,7 @@ 
 #include <odp/api/std_types.h>
 #include <odp/drv/shm.h>
 #include <_ishm_internal.h>
+#include <_ishmpool_internal.h>
 
 static inline uint32_t from_handle(odpdrv_shm_t shm)
 {
@@ -100,3 +101,46 @@  int odpdrv_shm_print_all(const char *title)
 {
 	return _odp_ishm_status(title);
 }
+
+odpdrv_shm_pool_t odpdrv_shm_pool_create(const char *pool_name,
+					 odpdrv_shm_pool_param_t *param)
+{
+	int flags;
+
+	/* force unique address for all ODP threads */
+	flags = _ODP_ISHM_SINGLE_VA;
+	return (odpdrv_shm_pool_t)_odp_ishm_pool_create(pool_name,
+							param->pool_size,
+							param->min_alloc,
+							param->max_alloc,
+							flags);
+}
+
+int odpdrv_shm_pool_destroy(odpdrv_shm_pool_t pool)
+{
+	return _odp_ishm_pool_destroy((_odp_ishm_pool_t *)(void*)pool);
+}
+
+odpdrv_shm_pool_t odpdrv_shm_pool_lookup(const char *name)
+{
+	return (odpdrv_shm_pool_t)_odp_ishm_pool_lookup(name);
+}
+
+void *odpdrv_shm_pool_alloc(odpdrv_shm_pool_t pool, uint64_t size)
+{
+	return _odp_ishm_pool_alloc((_odp_ishm_pool_t *)(void*)pool, size);
+}
+
+void odpdrv_shm_pool_free(odpdrv_shm_pool_t pool, void *addr)
+{
+	(void)_odp_ishm_pool_free((_odp_ishm_pool_t *)(void*)pool, addr);
+}
+
+int odpdrv_shm_pool_print(const char *title, odpdrv_shm_pool_t pool)
+{
+	return _odp_ishm_pool_status(title, (_odp_ishm_pool_t *)(void*)pool);
+}
+
+/**
+ * @}
+ */