[Beignet] [PATCH 08/11] Runtime: Apply base object to cl_context
junyan.he at inbox.com
junyan.he at inbox.com
Tue Jul 19 11:25:54 UTC 2016
From: Junyan He <junyan.he at intel.com>
Signed-off-by: Junyan He <junyan.he at intel.com>
---
src/cl_api.c | 2 +-
src/cl_context.c | 10 ++++------
src/cl_context.h | 9 +++++----
src/cl_utils.h | 2 +-
4 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/src/cl_api.c b/src/cl_api.c
index 73b4b66..06b5548 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -395,7 +395,7 @@ clGetContextInfo(cl_context context,
cl_uint n = 1;
FILL_GETINFO_RET (cl_uint, 1, &n, CL_SUCCESS);
} else if (param_name == CL_CONTEXT_REFERENCE_COUNT) {
- cl_uint ref = context->ref_n;
+ cl_uint ref = CL_OBJECT_GET_REF(context);
FILL_GETINFO_RET (cl_uint, 1, &ref, CL_SUCCESS);
} else if (param_name == CL_CONTEXT_PROPERTIES) {
if(context->prop_len > 0) {
diff --git a/src/cl_context.c b/src/cl_context.c
index a6bde7d..c6137a3 100644
--- a/src/cl_context.c
+++ b/src/cl_context.c
@@ -167,11 +167,9 @@ cl_context_new(struct _cl_context_prop *props)
cl_context ctx = NULL;
TRY_ALLOC_NO_ERR (ctx, CALLOC(struct _cl_context));
+ CL_OBJECT_INIT_BASE(ctx, CL_OBJECT_CONTEXT_MAGIC);
TRY_ALLOC_NO_ERR (ctx->drv, cl_driver_new(props));
- SET_ICD(ctx->dispatch)
ctx->props = *props;
- ctx->magic = CL_MAGIC_CONTEXT_HEADER;
- ctx->ref_n = 1;
ctx->ver = cl_driver_get_ver(ctx->drv);
pthread_mutex_init(&ctx->program_lock, NULL);
pthread_mutex_init(&ctx->queue_lock, NULL);
@@ -195,7 +193,7 @@ cl_context_delete(cl_context ctx)
return;
/* We are not done yet */
- if (atomic_dec(&ctx->ref_n) > 1)
+ if (CL_OBJECT_DEC_REF(ctx) > 1)
return;
/* delete the internal programs. */
@@ -227,7 +225,7 @@ cl_context_delete(cl_context ctx)
assert(ctx->drv);
cl_free(ctx->prop_user);
cl_driver_delete(ctx->drv);
- ctx->magic = CL_MAGIC_DEAD_HEADER; /* For safety */
+ CL_OBJECT_DESTROY_BASE(ctx);
cl_free(ctx);
}
@@ -235,7 +233,7 @@ LOCAL void
cl_context_add_ref(cl_context ctx)
{
assert(ctx);
- atomic_inc(&ctx->ref_n);
+ CL_OBJECT_INC_REF(ctx);
}
LOCAL cl_command_queue
diff --git a/src/cl_context.h b/src/cl_context.h
index 489e5d7..82444d2 100644
--- a/src/cl_context.h
+++ b/src/cl_context.h
@@ -24,7 +24,7 @@
#include "CL/cl_ext.h"
#include "cl_internals.h"
#include "cl_driver.h"
-#include "cl_khr_icd.h"
+#include "cl_base_object.h"
#include <stdint.h>
#include <pthread.h>
@@ -99,9 +99,7 @@ struct _cl_context_prop {
#define EGL_CTX(ctx) (EGLContext)(ctx->props.gl_context)
/* Encapsulate the whole device */
struct _cl_context {
- DEFINE_ICD(dispatch)
- uint64_t magic; /* To identify it as a context */
- volatile int ref_n; /* We reference count this object */
+ _cl_base_object base;
cl_driver drv; /* Handles HW or simulator */
cl_device_id device; /* All information about the GPU device */
cl_command_queue queues; /* All command queues currently allocated */
@@ -132,6 +130,9 @@ struct _cl_context {
};
+#define CL_OBJECT_CONTEXT_MAGIC 0x20BBCADE993134AALL
+#define CL_OBJECT_IS_CONTEXT(obj) (((cl_base_object)obj)->magic == CL_OBJECT_CONTEXT_MAGIC)
+
/* Implement OpenCL function */
extern cl_context cl_create_context(const cl_context_properties*,
cl_uint,
diff --git a/src/cl_utils.h b/src/cl_utils.h
index 43d15a3..dce9fd1 100644
--- a/src/cl_utils.h
+++ b/src/cl_utils.h
@@ -124,7 +124,7 @@ do { \
err = CL_INVALID_CONTEXT; \
goto error; \
} \
- if (UNLIKELY(CTX->magic != CL_MAGIC_CONTEXT_HEADER)) { \
+ if (UNLIKELY(!CL_OBJECT_IS_CONTEXT(CTX))) { \
err = CL_INVALID_CONTEXT; \
goto error; \
} \
--
1.7.9.5
____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
Check it out at http://www.inbox.com/marineaquarium
More information about the Beignet
mailing list