Test pass, thanks.

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of [email protected]
Sent: Monday, January 06, 2014 5:07 PM
To: [email protected]
Cc: Junyan He
Subject: [Beignet] [PATCH] Fix the multi-thread crash problem of batch buffer 
release.

From: Junyan He <[email protected]>

The case causes like this:
our thread hold the ref of the batch buffer, but have called cl_driver_delete 
to delete the bufmgr. So when we release the buffer object next time, the 
bufmgr's function pointer is invalid and cause the crash.
We now release the batch buffer before every time call the 
cl_set_thread_batch_buf.

Signed-off-by: Junyan He <[email protected]>
---
 src/cl_context.c   |    1 +
 src/cl_device_id.c |    2 ++
 2 files changed, 3 insertions(+)

diff --git a/src/cl_context.c b/src/cl_context.c index 1911bf2..8190e6a 100644
--- a/src/cl_context.c
+++ b/src/cl_context.c
@@ -203,6 +203,7 @@ cl_context_delete(cl_context ctx)
   assert(ctx->buffers == NULL);
   assert(ctx->drv);
   cl_free(ctx->prop_user);
+  cl_set_thread_batch_buf(NULL);
   cl_driver_delete(ctx->drv);
   ctx->magic = CL_MAGIC_DEAD_HEADER; /* For safety */
   cl_free(ctx);
diff --git a/src/cl_device_id.c b/src/cl_device_id.c index 7452f10..30d1639 
100644
--- a/src/cl_device_id.c
+++ b/src/cl_device_id.c
@@ -24,6 +24,7 @@
 #include "cl_driver.h"
 #include "cl_device_data.h"
 #include "cl_khr_icd.h"
+#include "cl_thread.h"
 #include "CL/cl.h"
 
 #include <assert.h>
@@ -72,6 +73,7 @@ LOCAL cl_device_id
 cl_get_gt_device(void)
 {
   cl_device_id ret = NULL;
+  cl_set_thread_batch_buf(NULL);
   const int device_id = cl_driver_get_device_id();
 
 #define DECL_INFO_STRING(STRUCT, FIELD, STRING) \
--
1.7.9.5

_______________________________________________
Beignet mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/beignet
_______________________________________________
Beignet mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/beignet

Reply via email to