[Beignet] [PATCH] Add the support for clSetMemObjectDestructorCallback API
Zhigang Gong
zhigang.gong at linux.intel.com
Mon Jul 15 23:10:24 PDT 2013
Pushed, thanks.
On Fri, Jul 12, 2013 at 08:13:08AM +0000, Xing, Homer wrote:
> This patch looks good to me.
>
> -----Original Message-----
> From: beignet-bounces+homer.xing=intel.com at lists.freedesktop.org [mailto:beignet-bounces+homer.xing=intel.com at lists.freedesktop.org] On Behalf Of junyan.he at inbox.com
> Sent: Friday, July 12, 2013 4:03 PM
> To: beignet at lists.freedesktop.org
> Cc: Junyan He
> Subject: [Beignet] [PATCH] Add the support for clSetMemObjectDestructorCallback API
>
> From: Junyan He <junyan.he at linux.intel.com>
>
> ---
> src/cl_api.c | 20 ++++++++++++++++++--
> src/cl_mem.c | 10 ++++++++++
> src/cl_mem.h | 7 +++++++
> 3 files changed, 35 insertions(+), 2 deletions(-)
>
> diff --git a/src/cl_api.c b/src/cl_api.c index 20cbc1e..03cad52 100644
> --- a/src/cl_api.c
> +++ b/src/cl_api.c
> @@ -585,8 +585,24 @@ clSetMemObjectDestructorCallback(cl_mem memobj,
> void (CL_CALLBACK *pfn_notify) (cl_mem, void*),
> void * user_data) {
> - NOT_IMPLEMENTED;
> - return 0;
> + cl_int err = CL_SUCCESS;
> + CHECK_MEM(memobj);
> + INVALID_VALUE_IF (pfn_notify == 0);
> +
> + cl_mem_dstr_cb *cb = (cl_mem_dstr_cb*)malloc(sizeof(cl_mem_dstr_cb));
> + if (!cb) {
> + err = CL_OUT_OF_HOST_MEMORY;
> + goto error;
> + }
> +
> + memset(cb, 0, sizeof(cl_mem_dstr_cb)); cb->pfn_notify = pfn_notify;
> + cb->user_data = user_data; cb->next = memobj->dstr_cb;
> + memobj->dstr_cb = cb;
> +
> +error:
> + return err;
> }
>
> cl_sampler
> diff --git a/src/cl_mem.c b/src/cl_mem.c index 9691ba3..5af16e0 100644
> --- a/src/cl_mem.c
> +++ b/src/cl_mem.c
> @@ -498,6 +498,16 @@ cl_mem_delete(cl_mem mem)
> if (mem->mapped_ptr)
> free(mem->mapped_ptr);
>
> + if (mem->dstr_cb) {
> + cl_mem_dstr_cb *cb = mem->dstr_cb;
> + while (mem->dstr_cb) {
> + cb = mem->dstr_cb;
> + cb->pfn_notify(mem, cb->user_data);
> + mem->dstr_cb = cb->next;
> + free(cb);
> + }
> + }
> +
> cl_free(mem);
> }
>
> diff --git a/src/cl_mem.h b/src/cl_mem.h index 66518a6..1b1709a 100644
> --- a/src/cl_mem.h
> +++ b/src/cl_mem.h
> @@ -55,6 +55,12 @@ typedef struct _cl_mapped_ptr {
> size_t size;
> }cl_mapped_ptr;
>
> +typedef struct _cl_mem_dstr_cb {
> + struct _cl_mem_dstr_cb * next;
> + void (CL_CALLBACK *pfn_notify)(cl_mem memobj, void *user_data);
> + void *user_data;
> +}cl_mem_dstr_cb;
> +
> /* Used for buffers and images */
> struct _cl_mem {
> DEFINE_ICD(dispatch)
> @@ -78,6 +84,7 @@ struct _cl_mem {
> cl_mapped_ptr* mapped_ptr;/* Store the mapped addresses and size by caller. */
> int mapped_ptr_sz; /* The array size of mapped_ptr. */
> int map_ref; /* The mapped count. */
> + cl_mem_dstr_cb *dstr_cb; /* The destroy callback. */
> };
>
> /* Query information about a memory object */
> --
> 1.7.9.5
>
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list