diff mbox

[v2] add implement for odp_shm_free

Message ID 201411192307264101426@linaro.org
State New
Headers show

Commit Message

yan.songming Nov. 19, 2014, 3:07 p.m. UTC
"return 0 on success, otherwise non-zero" May not very well.
Maybe we should change to this ?

  @retval 0 for success 
  @retval -1 on failure



yan.songming@linaro.org
 
From: Mike Holmes

Date: 2014-11-19 22:49
To: Yan Songming
CC: lng-odp
Subject: Re: [lng-odp] [PATCH v2] add implement for odp_shm_free
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(-)

--
1.8.3.1


_______________________________________________
lng-odp mailing list
lng-odp@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/lng-odp



-- 
Mike Holmes 
Linaro  Sr Technical Manager
LNG - ODP

Comments

Mike Holmes Nov. 19, 2014, 3:14 p.m. UTC | #1
Yes it should be that according to this
http://docs.opendataplane.org/arch/html/api_guide_lines.html#success



On 19 November 2014 10:07, yan.songming@linaro.org <yan.songming@linaro.org>
wrote:

> "return 0 on success, otherwise non-zero" May not very well.
> Maybe we should change to this ?
>
>   @retval 0 for success
>   @retval -1 on failure
>
> ------------------------------
> yan.songming@linaro.org
>
>
> *From:* Mike Holmes <mike.holmes@linaro.org>
> *Date:* 2014-11-19 22:49
> *To:* Yan Songming <yan.songming@linaro.org>
> *CC:* lng-odp <lng-odp@lists.linaro.org>
> *Subject:* Re: [lng-odp] [PATCH v2] add implement for odp_shm_free
> 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
>>
>
>
>
> --
> *Mike Holmes*
> Linaro  Sr Technical Manager
> 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;