Message ID | 1416467568-20380-1-git-send-email-yan.songming@linaro.org |
---|---|
State | Accepted |
Commit | ce8ca2b5b0c37dd7b3b24e2d2a9cb89a575a60e7 |
Headers | show |
On 20 November 2014 02:12, Yan Sonming <yan.songming@linaro.org> wrote: > 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> > --- > v4 add more information about the retval and change the subject of this > patch. > v3 change the return value of odp_shm_free. > v2 fix the problem which Maxim found. > --- > .../linux-generic/include/api/odp_shared_memory.h | 5 +-- > 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 ff6f9a9..26e208b 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 24a5d60..0721292 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; > -- > 1.8.3.1 > > > _______________________________________________ > lng-odp mailing list > lng-odp@lists.linaro.org > http://lists.linaro.org/mailman/listinfo/lng-odp >
Merged. s/platform/linux-generic/ Maxim. On 11/22/2014 01:42 AM, Mike Holmes wrote: > > > On 20 November 2014 02:12, Yan Sonming <yan.songming@linaro.org > <mailto:yan.songming@linaro.org>> wrote: > > 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 > <mailto:yan.songming@linaro.org>> > > > Reviewed-by: Mike Holmes <mike.holmes@linaro.org > <mailto:mike.holmes@linaro.org>> > > --- > v4 add more information about the retval and change the subject of > this patch. > v3 change the return value of odp_shm_free. > v2 fix the problem which Maxim found. > --- > .../linux-generic/include/api/odp_shared_memory.h | 5 +-- > 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 ff6f9a9..26e208b 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 24a5d60..0721292 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; > -- > 1.8.3.1 > > > _______________________________________________ > lng-odp mailing list > lng-odp@lists.linaro.org <mailto:lng-odp@lists.linaro.org> > http://lists.linaro.org/mailman/listinfo/lng-odp > > > > > -- > *Mike Holmes* > Linaro Sr Technical Manager > LNG - ODP > > > _______________________________________________ > lng-odp mailing list > lng-odp@lists.linaro.org > http://lists.linaro.org/mailman/listinfo/lng-odp
diff --git a/platform/linux-generic/include/api/odp_shared_memory.h b/platform/linux-generic/include/api/odp_shared_memory.h index ff6f9a9..26e208b 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 24a5d60..0721292 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;
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> --- v4 add more information about the retval and change the subject of this patch. v3 change the return value of odp_shm_free. v2 fix the problem which Maxim found. --- .../linux-generic/include/api/odp_shared_memory.h | 5 +-- platform/linux-generic/odp_shared_memory.c | 42 ++++++++++++++++++---- 2 files changed, 39 insertions(+), 8 deletions(-)