[Beignet] [PATCH V2] Fix event pthread_mutex_lock dead lock.
Zhigang Gong
zhigang.gong at linux.intel.com
Tue Aug 13 22:37:26 PDT 2013
This version LGTM, pushed, thanks.
On Wed, Aug 14, 2013 at 11:08:01AM +0800, Yang Rong wrote:
> In function cl_event_set_status, between pthread_mutex_lock and pthread_mutex_unlock
> will call cl_event_delete, which also require the same lock, cause deak lock.
> Unlock it before call cl_event_delete.
>
> Signed-off-by: Yang Rong <rong.r.yang at intel.com>
> ---
> src/cl_event.c | 21 +++++++++++++++++----
> 1 file changed, 17 insertions(+), 4 deletions(-)
>
> diff --git a/src/cl_event.c b/src/cl_event.c
> index 48f24e5..e882c7c 100644
> --- a/src/cl_event.c
> +++ b/src/cl_event.c
> @@ -305,23 +305,36 @@ void cl_event_set_status(cl_event event, cl_int status)
>
> pthread_mutex_lock(&event->ctx->event_lock);
> if(status >= event->status) {
> - return;
> + pthread_mutex_unlock(&event->ctx->event_lock);
> + return;
> + }
> + if(event->status <= CL_COMPLETE) {
> + event->status = status; //have done enqueue before or doing in another thread
> + pthread_mutex_unlock(&event->ctx->event_lock);
> + return;
> }
>
> if(status <= CL_COMPLETE) {
> if(event->enqueue_cb) {
> + cl_enqueue_handle(&event->enqueue_cb->data);
> + event->status = status; //Change the event status after enqueue and befor unlock
> +
> + pthread_mutex_unlock(&event->ctx->event_lock);
> for(i=0; i<event->enqueue_cb->num_events; i++)
> cl_event_delete(event->enqueue_cb->wait_list[i]);
> + pthread_mutex_lock(&event->ctx->event_lock);
>
> - cl_enqueue_handle(&event->enqueue_cb->data);
> cl_free(event->enqueue_cb);
> event->enqueue_cb = NULL;
> }
> - cl_event_delete(event);
> }
> - event->status = status;
> + if(event->status >= status) //maybe changed in other threads
> + event->status = status;
> pthread_mutex_unlock(&event->ctx->event_lock);
>
> + if(event->status <= CL_COMPLETE)
> + cl_event_delete(event);
> +
> /* Call user callback */
> user_cb = event->user_cb;
> while(user_cb) {
> --
> 1.7.10.4
>
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list