diff mbox

[v2] add implement for odp_shm_free

Message ID 1416405598-12262-1-git-send-email-yan.songming@linaro.org
State New
Headers show

Commit Message

yan.songming Nov. 19, 2014, 1:59 p.m. UTC
New API implementing odp_shm_free to match the odp_shm_reserve.

Signed-off-by: Yan Songming <yan.songming@linaro.org>
---
v2 fix the problem which Maxim found.
---
 platform/linux-generic/odp_shared_memory.c | 43 +++++++++++++++++++++++++-----
 1 file changed, 37 insertions(+), 6 deletions(-)

Comments

Mike Holmes Nov. 19, 2014, 2:49 p.m. UTC | #1
The current header file lists failure as 1 in doxygen so we need to change
the description in the header file in this patch

http://docs.opendataplane.org/arch/html/group__odp__shared__memory.html



On 19 November 2014 08:59, Yan Songming <yan.songming@linaro.org> wrote:

> New API implementing odp_shm_free to match the odp_shm_reserve.
>
> Signed-off-by: Yan Songming <yan.songming@linaro.org>
> ---
> v2 fix the problem which Maxim found.
> ---
>  platform/linux-generic/odp_shared_memory.c | 43
> +++++++++++++++++++++++++-----
>  1 file changed, 37 insertions(+), 6 deletions(-)
>
> diff --git a/platform/linux-generic/odp_shared_memory.c
> b/platform/linux-generic/odp_shared_memory.c
> index 24a5d60..a1321bf 100644
> --- a/platform/linux-generic/odp_shared_memory.c
> +++ b/platform/linux-generic/odp_shared_memory.c
> @@ -114,6 +114,43 @@ 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 (odp_shm_tbl->block[i].addr == NULL) {
> +               /* free block */
> +               ODP_DBG("odp_shm_free: Free block failed\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 +258,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;
> --
> 1.8.3.1
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
>
diff mbox

Patch

diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-generic/odp_shared_memory.c
index 24a5d60..a1321bf 100644
--- a/platform/linux-generic/odp_shared_memory.c
+++ b/platform/linux-generic/odp_shared_memory.c
@@ -114,6 +114,43 @@  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 (odp_shm_tbl->block[i].addr == NULL) {
+		/* free block */
+		ODP_DBG("odp_shm_free: Free block failed\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 +258,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;