[07/11] Runtime: Apply base object to cl_event

Submitted by junyan.he@inbox.com on July 19, 2016, 11:25 a.m.

Details

Message ID 1468927557-5051-7-git-send-email-junyan.he@inbox.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Beignet

Browsing this patch as part of:
"Series without cover letter" rev 1 in Beignet
<< prev patch [7/11] next patch >>

Commit Message

junyan.he@inbox.com July 19, 2016, 11:25 a.m.
From: Junyan He <junyan.he@intel.com>

Signed-off-by: Junyan He <junyan.he@intel.com>
---
 src/cl_api.c   |    2 +-
 src/cl_event.c |   10 +++++-----
 src/cl_event.h |    9 +++++----
 src/cl_utils.h |    2 +-
 4 files changed, 12 insertions(+), 11 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/cl_api.c b/src/cl_api.c
index 3a2b013..73b4b66 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -1408,7 +1408,7 @@  clGetEventInfo(cl_event      event,
     cl_event_update_status(event, 0);
     FILL_GETINFO_RET (cl_int, 1, &event->status, CL_SUCCESS);
   } else if (param_name == CL_EVENT_REFERENCE_COUNT) {
-    cl_uint ref = event->ref_n;
+    cl_uint ref = CL_OBJECT_GET_REF(event);
     FILL_GETINFO_RET (cl_int, 1, &ref, CL_SUCCESS);
   } else {
     return CL_INVALID_VALUE;
diff --git a/src/cl_event.c b/src/cl_event.c
index a2aacea..cf3cc3a 100644
--- a/src/cl_event.c
+++ b/src/cl_event.c
@@ -99,9 +99,7 @@  cl_event cl_event_new(cl_context ctx, cl_command_queue queue, cl_command_type ty
 
   /* Allocate and inialize the structure itself */
   TRY_ALLOC_NO_ERR (event, CALLOC(struct _cl_event));
-  SET_ICD(event->dispatch)
-  event->magic = CL_MAGIC_EVENT_HEADER;
-  event->ref_n = 1;
+  CL_OBJECT_INIT_BASE(event, CL_OBJECT_EVENT_MAGIC);
 
   /* Append the event in the context event list */
   pthread_mutex_lock(&ctx->event_lock);
@@ -146,7 +144,7 @@  void cl_event_delete(cl_event event)
 
   cl_event_update_status(event, 0);
 
-  if (atomic_dec(&event->ref_n) > 1)
+  if (CL_OBJECT_DEC_REF(event) > 1)
     return;
 
   /* Call all user's callback if haven't execute */
@@ -176,13 +174,15 @@  void cl_event_delete(cl_event event)
     cl_gpgpu_delete(event->gpgpu);
     event->gpgpu = NULL;
   }
+
+  CL_OBJECT_DESTROY_BASE(event);
   cl_free(event);
 }
 
 void cl_event_add_ref(cl_event event)
 {
   assert(event);
-  atomic_inc(&event->ref_n);
+  CL_OBJECT_INC_REF(event);
 }
 
 cl_int cl_event_set_callback(cl_event event ,
diff --git a/src/cl_event.h b/src/cl_event.h
index 67fab19..164ca47 100644
--- a/src/cl_event.h
+++ b/src/cl_event.h
@@ -22,7 +22,7 @@ 
 
 #include <semaphore.h>
 
-#include "cl_internals.h"
+#include "cl_base_object.h"
 #include "cl_driver.h"
 #include "cl_enqueue.h"
 #include "CL/cl.h"
@@ -55,9 +55,7 @@  typedef struct _user_callback {
 } user_callback;
 
 struct _cl_event {
-  DEFINE_ICD(dispatch)
-  uint64_t           magic;       /* To identify it as a sampler object */
-  volatile int       ref_n;       /* We reference count this object */
+  _cl_base_object    base;
   cl_context         ctx;         /* The context associated with event */
   cl_event           prev, next;  /* We chain the memory buffers together */
   cl_command_queue   queue;       /* The command queue associated with event */
@@ -74,6 +72,9 @@  struct _cl_event {
   cl_event   last_next, last_prev;/* We need a list to monitor untouchable api event*/
 };
 
+#define CL_OBJECT_EVENT_MAGIC 0x8324a9f810ebf90fLL
+#define CL_OBJECT_IS_EVENT(obj) (((cl_base_object)obj)->magic == CL_OBJECT_EVENT_MAGIC)
+
 /* Create a new event object */
 cl_event cl_event_new(cl_context, cl_command_queue, cl_command_type, cl_bool);
 /* Unref the object and delete it if no more reference on it */
diff --git a/src/cl_utils.h b/src/cl_utils.h
index c7742cb..43d15a3 100644
--- a/src/cl_utils.h
+++ b/src/cl_utils.h
@@ -215,7 +215,7 @@  do {                                                        \
       err = CL_INVALID_EVENT;                                 \
       goto error;                                             \
     }                                                         \
-    if (UNLIKELY(EVENT->magic != CL_MAGIC_EVENT_HEADER)) {    \
+    if (UNLIKELY(!CL_OBJECT_IS_EVENT(EVENT))) {              \
       err = CL_INVALID_EVENT;                                 \
       goto error;                                             \
     }                                                         \