From: Junyan He <junyan...@intel.com>

The CL object with ref == 0 should be considered
as a invalid object.

Signed-off-by: Junyan He <junyan...@intel.com>
---
 src/cl_command_queue.h | 4 +++-
 src/cl_context.h       | 4 +++-
 src/cl_device_id.h     | 4 +++-
 src/cl_kernel.h        | 4 +++-
 src/cl_platform_id.h   | 4 +++-
 src/cl_program.h       | 4 +++-
 src/cl_sampler.h       | 4 +++-
 7 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/src/cl_command_queue.h b/src/cl_command_queue.h
index 470cafb..42ea7b2 100644
--- a/src/cl_command_queue.h
+++ b/src/cl_command_queue.h
@@ -59,7 +59,9 @@ struct _cl_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)
+#define CL_OBJECT_IS_COMMAND_QUEUE(obj) ((obj &&                           \
+         ((cl_base_object)obj)->magic == CL_OBJECT_COMMAND_QUEUE_MAGIC &&  \
+         CL_OBJECT_GET_REF(obj) >= 1))
 
 /* The macro to get the thread specified gpgpu struct. */
 #define GET_QUEUE_THREAD_GPGPU(queue) \
diff --git a/src/cl_context.h b/src/cl_context.h
index b1602c8..b2903a7 100644
--- a/src/cl_context.h
+++ b/src/cl_context.h
@@ -132,7 +132,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)
+#define CL_OBJECT_IS_CONTEXT(obj) ((obj &&                           \
+         ((cl_base_object)obj)->magic == CL_OBJECT_CONTEXT_MAGIC &&  \
+         CL_OBJECT_GET_REF(obj) >= 1))
 
 extern void cl_context_add_queue(cl_context ctx, cl_command_queue queue);
 extern void cl_context_remove_queue(cl_context ctx, cl_command_queue queue);
diff --git a/src/cl_device_id.h b/src/cl_device_id.h
index abb6403..8cd55bb 100644
--- a/src/cl_device_id.h
+++ b/src/cl_device_id.h
@@ -126,7 +126,9 @@ struct _cl_device_id {
 };
 
 #define CL_OBJECT_DEVICE_MAGIC 0x2acaddcca8853c52LL
-#define CL_OBJECT_IS_DEVICE(obj) (((cl_base_object)obj)->magic == 
CL_OBJECT_DEVICE_MAGIC)
+#define CL_OBJECT_IS_DEVICE(obj) ((obj &&                           \
+         ((cl_base_object)obj)->magic == CL_OBJECT_DEVICE_MAGIC &&  \
+         CL_OBJECT_GET_REF(obj) >= 1))
 
 /* Get a device from the given platform */
 extern cl_int cl_get_device_ids(cl_platform_id    platform,
diff --git a/src/cl_kernel.h b/src/cl_kernel.h
index dd5a842..0aa4a4f 100644
--- a/src/cl_kernel.h
+++ b/src/cl_kernel.h
@@ -73,7 +73,9 @@ struct _cl_kernel {
 };
 
 #define CL_OBJECT_KERNEL_MAGIC 0x1234567890abedefLL
-#define CL_OBJECT_IS_KERNEL(obj) (((cl_base_object)obj)->magic == 
CL_OBJECT_KERNEL_MAGIC)
+#define CL_OBJECT_IS_KERNEL(obj) ((obj &&                           \
+         ((cl_base_object)obj)->magic == CL_OBJECT_KERNEL_MAGIC &&  \
+         CL_OBJECT_GET_REF(obj) >= 1))
 
 /* Allocate an empty kernel */
 extern cl_kernel cl_kernel_new(cl_program);
diff --git a/src/cl_platform_id.h b/src/cl_platform_id.h
index 11e90d0..aaba624 100644
--- a/src/cl_platform_id.h
+++ b/src/cl_platform_id.h
@@ -45,7 +45,9 @@ struct _cl_platform_id {
 };
 
 #define CL_OBJECT_PLATFORM_MAGIC 0xaacdbb00123ccd85LL
-#define CL_OBJECT_IS_PLATFORM(obj) (((cl_base_object)obj)->magic == 
CL_OBJECT_PLATFORM_MAGIC)
+#define CL_OBJECT_IS_PLATFORM(obj) ((obj &&                           \
+         ((cl_base_object)obj)->magic == CL_OBJECT_PLATFORM_MAGIC &&  \
+         CL_OBJECT_GET_REF(obj) >= 1))
 
 /* Return the default platform */
 extern cl_platform_id cl_get_platform_default(void);
diff --git a/src/cl_program.h b/src/cl_program.h
index 85f8df3..cf9615c 100644
--- a/src/cl_program.h
+++ b/src/cl_program.h
@@ -75,7 +75,9 @@ struct _cl_program {
 };
 
 #define CL_OBJECT_PROGRAM_MAGIC 0x34562ab12789cdefLL
-#define CL_OBJECT_IS_PROGRAM(obj) (((cl_base_object)obj)->magic == 
CL_OBJECT_PROGRAM_MAGIC)
+#define CL_OBJECT_IS_PROGRAM(obj) ((obj &&                           \
+         ((cl_base_object)obj)->magic == CL_OBJECT_PROGRAM_MAGIC &&  \
+         CL_OBJECT_GET_REF(obj) >= 1))
 
 /* Create a empty program */
 extern cl_program cl_program_new(cl_context);
diff --git a/src/cl_sampler.h b/src/cl_sampler.h
index 08d03fd..25d1863 100644
--- a/src/cl_sampler.h
+++ b/src/cl_sampler.h
@@ -36,7 +36,9 @@ struct _cl_sampler {
 };
 
 #define CL_OBJECT_SAMPLER_MAGIC 0x686a0ecba79ce32fLL
-#define CL_OBJECT_IS_SAMPLER(obj) (((cl_base_object)obj)->magic == 
CL_OBJECT_SAMPLER_MAGIC)
+#define CL_OBJECT_IS_SAMPLER(obj) ((obj &&                           \
+         ((cl_base_object)obj)->magic == CL_OBJECT_SAMPLER_MAGIC &&  \
+         CL_OBJECT_GET_REF(obj) >= 1))
 
 /* Create a new sampler object */
 extern cl_sampler cl_sampler_new(cl_context,
-- 
2.7.4



_______________________________________________
Beignet mailing list
Beignet@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/beignet

Reply via email to