From 110a7c280bf9feffe7df9ca765287eb31395dd5a Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Mon, 13 Jun 2005 00:32:11 +0000 Subject: **BUGFIX** fix deadlock with _x_flush_events_queues CVS patchset: 7621 CVS date: 2005/06/13 00:32:11 --- src/xine-engine/events.c | 5 ++++- src/xine-engine/xine.c | 9 +++++++-- src/xine-engine/xine_internal.h | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/xine-engine/events.c b/src/xine-engine/events.c index 61fd01e04..e7aa28772 100644 --- a/src/xine-engine/events.c +++ b/src/xine-engine/events.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: events.c,v 1.26 2004/04/16 16:34:22 hadess Exp $ + * $Id: events.c,v 1.27 2005/06/13 00:32:12 miguelfreitas Exp $ * * Event handling functions * @@ -116,6 +116,7 @@ xine_event_queue_t *xine_event_new_queue (xine_stream_t *stream) { queue->events = xine_list_new (); queue->stream = stream; queue->listener_thread = NULL; + queue->callback_running = 0; pthread_mutex_lock (&stream->event_queues_lock); xine_list_append_content (stream->event_queues, queue); @@ -200,7 +201,9 @@ static void *listener_loop (void *queue_gen) { if (event->type == XINE_EVENT_QUIT) running = 0; + queue->callback_running = 1; queue->callback (queue->user_data, event); + queue->callback_running = 0; xine_event_free (event); diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index f9639e89e..7a701cf22 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xine.c,v 1.312 2005/03/06 11:08:40 tmattern Exp $ + * $Id: xine.c,v 1.313 2005/06/13 00:32:13 miguelfreitas Exp $ */ /* @@ -624,7 +624,12 @@ void _x_flush_events_queues (xine_stream_t *stream) { pthread_mutex_lock (&queue->lock); pthread_mutex_unlock (&stream->event_queues_lock); - if (queue->listener_thread != NULL) { + /* we might have been called from the very same function that + * processes events, therefore waiting here would cause deadlock. + * check only queues with listener threads which are not + * currently executing their callback functions. + */ + if (queue->listener_thread != NULL && !queue->callback_running) { while (!xine_list_is_empty (queue->events)) { pthread_cond_wait (&queue->events_processed, &queue->lock); } diff --git a/src/xine-engine/xine_internal.h b/src/xine-engine/xine_internal.h index 2c511d127..301b79a8a 100644 --- a/src/xine-engine/xine_internal.h +++ b/src/xine-engine/xine_internal.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xine_internal.h,v 1.164 2005/02/09 20:03:21 tmattern Exp $ + * $Id: xine_internal.h,v 1.165 2005/06/13 00:32:15 miguelfreitas Exp $ * */ @@ -182,6 +182,7 @@ struct xine_event_queue_s { xine_stream_t *stream; pthread_t *listener_thread; xine_event_listener_cb_t callback; + int callback_running; void *user_data; }; -- cgit v1.2.3