From: Reinhard N. <rn...@gm...> - 2010-07-14 20:42:08
|
# HG changeset patch # User Reinhard Nißl <rn...@gm...> # Date 1278957160 -7200 # Node ID abbd3a39d7a00dde733c9bedc4acad36ff1513b5 # Parent 09bdc8cb417c573b3ad2d8d0b189d392f3f1b11b Fix deadlock while switching to/from fullscreen mode. When the video output driver (e. g. vdpau) has no need to use XLockDisplay() to synchronize its output operation, it is likely that we get an output callback while we are about to change the drawable and hence deadlock. Using a timed lock avoids the deadlock and the callback returns immediately. As we are about to change drawable anyway, leaving the callback early doesn't matter at that time. diff --git a/src/xitk/videowin.c b/src/xitk/videowin.c --- a/src/xitk/videowin.c +++ b/src/xitk/videowin.c @@ -1196,7 +1196,25 @@ double *dest_pixel_aspect, int *win_x, int *win_y) { - pthread_mutex_lock(&gVw.mutex); + int ms_timeout = 5; + struct timespec timeout; + struct timeval now; + gettimeofday(&now, 0); + + timeout.tv_sec = now.tv_sec + ms_timeout / 1000; + timeout.tv_nsec = now.tv_usec * 1000 + (ms_timeout % 1000) * 1e6; + + if (timeout.tv_nsec > 1e9) + { + timeout.tv_nsec -= 1e9; + timeout.tv_sec++; + } + + /* if this callback happens while we are about to change the drawable + * then we'll deadlock here. Using a timed lock of 5 ms avoids this. + */ + if (0 != pthread_mutex_timedlock(&gVw.mutex, &timeout)) + return; gVw.frame_width = video_width; gVw.frame_height = video_height; |