[09/11] Runtime: Apply base object to cl_command_queue.

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

Details

Message ID 1468927557-5051-9-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 [9/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_command_queue.c |   10 ++++------
 src/cl_command_queue.h |    8 +++++---
 src/cl_utils.h         |    2 +-
 4 files changed, 11 insertions(+), 11 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/cl_api.c b/src/cl_api.c
index 06b5548..790e692 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -472,7 +472,7 @@  clGetCommandQueueInfo(cl_command_queue       command_queue,
   } else if (param_name == CL_QUEUE_DEVICE) {
     FILL_GETINFO_RET (cl_device_id, 1, &command_queue->ctx->device, CL_SUCCESS);
   } else if (param_name == CL_QUEUE_REFERENCE_COUNT) {
-    cl_uint ref = command_queue->ref_n;
+    cl_uint ref = CL_OBJECT_GET_REF(command_queue);
     FILL_GETINFO_RET (cl_uint, 1, &ref, CL_SUCCESS);
   } else if (param_name == CL_QUEUE_PROPERTIES) {
     FILL_GETINFO_RET (cl_command_queue_properties, 1, &command_queue->props, CL_SUCCESS);
diff --git a/src/cl_command_queue.c b/src/cl_command_queue.c
index b66928f..172ea94 100644
--- a/src/cl_command_queue.c
+++ b/src/cl_command_queue.c
@@ -44,9 +44,7 @@  cl_command_queue_new(cl_context ctx)
 
   assert(ctx);
   TRY_ALLOC_NO_ERR (queue, CALLOC(struct _cl_command_queue));
-  SET_ICD(queue->dispatch)
-  queue->magic = CL_MAGIC_QUEUE_HEADER;
-  queue->ref_n = 1;
+  CL_OBJECT_INIT_BASE(queue, CL_OBJECT_COMMAND_QUEUE_MAGIC);
   queue->ctx = ctx;
   queue->cmrt_event = NULL;
   if ((queue->thread_data = cl_thread_data_create()) == NULL) {
@@ -76,7 +74,7 @@  LOCAL void
 cl_command_queue_delete(cl_command_queue queue)
 {
   assert(queue);
-  if (atomic_dec(&queue->ref_n) != 1) return;
+  if (CL_OBJECT_DEC_REF(queue) != 1) return;
 
 #ifdef HAS_CMRT
   if (queue->cmrt_event != NULL)
@@ -103,14 +101,14 @@  cl_command_queue_delete(cl_command_queue queue)
   cl_context_delete(queue->ctx);
   cl_free(queue->wait_events);
   cl_free(queue->barrier_events);
-  queue->magic = CL_MAGIC_DEAD_HEADER; /* For safety */
+  CL_OBJECT_DESTROY_BASE(queue);
   cl_free(queue);
 }
 
 LOCAL void
 cl_command_queue_add_ref(cl_command_queue queue)
 {
-  atomic_inc(&queue->ref_n);
+  CL_OBJECT_INC_REF(queue);
 }
 
 static void
diff --git a/src/cl_command_queue.h b/src/cl_command_queue.h
index d1b8c44..72b7c55 100644
--- a/src/cl_command_queue.h
+++ b/src/cl_command_queue.h
@@ -23,6 +23,7 @@ 
 #include "cl_internals.h"
 #include "cl_driver.h"
 #include "cl_thread.h"
+#include "cl_base_object.h"
 #include "CL/cl.h"
 #include <stdint.h>
 
@@ -30,9 +31,7 @@  struct intel_gpgpu;
 
 /* Basically, this is a (kind-of) batch buffer */
 struct _cl_command_queue {
-  DEFINE_ICD(dispatch)
-  uint64_t magic;                      /* To identify it as a command queue */
-  volatile int ref_n;                  /* We reference count this object */
+  _cl_base_object base;
   cl_context ctx;                      /* Its parent context */
   cl_event* barrier_events;               /* Point to array of non-complete user events that block this command queue */
   cl_int    barrier_events_num;           /* Number of Non-complete user events */
@@ -48,6 +47,9 @@  struct _cl_command_queue {
   void* cmrt_event;                    /* the latest CmEvent* of the command queue */
 };
 
+#define CL_OBJECT_COMMAND_QUEUE_MAGIC 0x83650a12b79ce4efLL
+#define CL_OBJECT_IS_COMMAND_QUEUE(obj) (((cl_base_object)obj)->magic == CL_OBJECT_COMMAND_QUEUE_MAGIC)
+
 /* The macro to get the thread specified gpgpu struct. */
 #define GET_QUEUE_THREAD_GPGPU(queue) \
 	cl_gpgpu gpgpu = queue ? cl_get_thread_gpgpu(queue) : NULL;  \
diff --git a/src/cl_utils.h b/src/cl_utils.h
index dce9fd1..02ccc72 100644
--- a/src/cl_utils.h
+++ b/src/cl_utils.h
@@ -136,7 +136,7 @@  do {                                                        \
     err = CL_INVALID_COMMAND_QUEUE;                         \
     goto error;                                             \
   }                                                         \
-  if (UNLIKELY(QUEUE->magic != CL_MAGIC_QUEUE_HEADER)) {    \
+  if (UNLIKELY(!CL_OBJECT_IS_COMMAND_QUEUE(QUEUE))) {      \
     err = CL_INVALID_COMMAND_QUEUE;                         \
     goto error;                                             \
   }                                                         \