diff options
author | Yan Sonming <yan.songming@linaro.org> | 2014-11-20 02:12:48 -0500 |
---|---|---|
committer | Maxim Uvarov <maxim.uvarov@linaro.org> | 2014-11-22 15:54:19 +0300 |
commit | ce8ca2b5b0c37dd7b3b24e2d2a9cb89a575a60e7 (patch) | |
tree | 29f6a8b07808d15fe5e967860349a69eb03fb3df /platform | |
parent | f2b27fa3a37fbed61825e8f8a942c8c2206a5ab9 (diff) |
linux-generic: odp_shared_memory.c: implement func odp_shm_free
New API implementing odp_shm_free to match the odp_shm_reserve.
Fix retval for odp_shm_free.
Signed-off-by: Yan Songming <yan.songming@linaro.org>
Reviewed-by: Mike Holmes <mike.holmes@linaro.org>
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'platform')
-rw-r--r-- | platform/linux-generic/include/api/odp_shared_memory.h | 5 | ||||
-rw-r--r-- | platform/linux-generic/odp_shared_memory.c | 42 |
2 files changed, 39 insertions, 8 deletions
diff --git a/platform/linux-generic/include/api/odp_shared_memory.h b/platform/linux-generic/include/api/odp_shared_memory.h index ff6f9a912..26e208b9a 100644 --- a/platform/linux-generic/include/api/odp_shared_memory.h +++ b/platform/linux-generic/include/api/odp_shared_memory.h @@ -80,8 +80,9 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, * * @param[in] shm Block handle * - * @retval 0 for success - * @retval 1 on failure + * @retval 0 if the handle is already free + * @retval 0 if the handle free succeeds + * @retval -1 on failure to free the handle */ int odp_shm_free(odp_shm_t shm); diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-generic/odp_shared_memory.c index 9d3e4cb2d..4bcf73e92 100644 --- a/platform/linux-generic/odp_shared_memory.c +++ b/platform/linux-generic/odp_shared_memory.c @@ -114,6 +114,42 @@ static int find_block(const char *name, uint32_t *index) return 0; } +int odp_shm_free(odp_shm_t shm) +{ + uint32_t i; + int ret; + odp_shm_block_t *shm_block; + uint64_t alloc_size; + + i = from_handle(shm); + if (NULL == odp_shm_tbl->block[i].addr) { + ODP_DBG("odp_shm_free: Free block\n"); + return 0; + } + + odp_spinlock_lock(&odp_shm_tbl->lock); + shm_block = &odp_shm_tbl->block[i]; + + alloc_size = shm_block->size + shm_block->align; + ret = munmap(shm_block->addr, alloc_size); + if (0 != ret) { + ODP_DBG("odp_shm_free: munmap failed\n"); + odp_spinlock_unlock(&odp_shm_tbl->lock); + return -1; + } + + if (shm_block->flags & ODP_SHM_PROC) { + ret = shm_unlink(shm_block->name); + if (0 != ret) { + ODP_DBG("odp_shm_free: shm_unlink failed\n"); + odp_spinlock_unlock(&odp_shm_tbl->lock); + return -1; + } + } + memset(&odp_shm_tbl->block[i], 0, sizeof(odp_shm_block_t)); + odp_spinlock_unlock(&odp_shm_tbl->lock); + return 0; +} odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, uint32_t flags) @@ -221,12 +257,6 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, return block->hdl; } -int odp_shm_free(odp_shm_t shm ODP_UNUSED) -{ - ODP_UNIMPLEMENTED(); - return 0; -} - odp_shm_t odp_shm_lookup(const char *name) { uint32_t i; |