Change subject to something like this:
platform: odp_shared_memory.c: implement odp_shm_free

Nit: This should really go as two patches with the commit messages below.
1. api: doxygen: fix retval for odp_shm_free
2. platform: odp_shared_memory.c: implement func odp_shm_free

On 2014-11-19 23:36, Yan Songming wrote:
> New API implementing odp_shm_free to match the odp_shm_reserve.
> 
> Signed-off-by: Yan Songming <[email protected]>
> ---
> v3 change the return value of odp_shm_free.
> v2 fix the problem which Maxim found.
> ---
>  .../linux-generic/include/api/odp_shared_memory.h  |  2 +-
>  platform/linux-generic/odp_shared_memory.c         | 43 
> +++++++++++++++++++---
>  2 files changed, 38 insertions(+), 7 deletions(-)
> 
> diff --git a/platform/linux-generic/include/api/odp_shared_memory.h 
> b/platform/linux-generic/include/api/odp_shared_memory.h
> index ff6f9a9..d42e272 100644
> --- a/platform/linux-generic/include/api/odp_shared_memory.h
> +++ b/platform/linux-generic/include/api/odp_shared_memory.h
> @@ -81,7 +81,7 @@ 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 -1 on failure
>   */
>  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 24a5d60..bc0ab55 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\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) {

Don't we need to ODP_SHM_SW_ONLY as well?

Cheers,
Anders

_______________________________________________
lng-odp mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to