Avoid use of pthread_cancel() for redraw thread cancellation. Use an extra

variable to acknowledge cancellation. This avoids Xserver events queue
corruption when clipboard is in use. Concretely, this fixes following errors:
Xlib: unexpected async reply (sequence 0xHEX)!
This commit is contained in:
gbeauche 2005-03-21 23:57:34 +00:00
parent 2871aefa87
commit 04a331e827

View File

@ -99,6 +99,7 @@ static bool redraw_thread_active = false; // Flag: Redraw thread installed
#ifdef HAVE_PTHREADS #ifdef HAVE_PTHREADS
static pthread_attr_t redraw_thread_attr; // Redraw thread attributes static pthread_attr_t redraw_thread_attr; // Redraw thread attributes
static volatile bool redraw_thread_cancel; // Flag: Cancel Redraw thread static volatile bool redraw_thread_cancel; // Flag: Cancel Redraw thread
static volatile bool redraw_thread_cancel_ack; // Flag: Acknowledge for redraw thread cancellation
static pthread_t redraw_thread; // Redraw thread static pthread_t redraw_thread; // Redraw thread
#endif #endif
@ -1720,10 +1721,9 @@ void X11_monitor_desc::video_close(void)
#ifdef HAVE_PTHREADS #ifdef HAVE_PTHREADS
if (redraw_thread_active) { if (redraw_thread_active) {
redraw_thread_cancel = true; redraw_thread_cancel = true;
#ifdef HAVE_PTHREAD_CANCEL redraw_thread_cancel_ack = false;
pthread_cancel(redraw_thread);
#endif
pthread_join(redraw_thread, NULL); pthread_join(redraw_thread, NULL);
while (!redraw_thread_cancel_ack) ;
} }
#endif #endif
redraw_thread_active = false; redraw_thread_active = false;
@ -2611,6 +2611,8 @@ static void *redraw_func(void *arg)
uint64 end = GetTicks_usec(); uint64 end = GetTicks_usec();
D(bug("%Ld refreshes in %Ld usec = %f refreshes/sec\n", ticks, end - start, ticks * 1000000.0 / (end - start))); D(bug("%Ld refreshes in %Ld usec = %f refreshes/sec\n", ticks, end - start, ticks * 1000000.0 / (end - start)));
redraw_thread_cancel_ack = true;
return NULL; return NULL;
} }
#endif #endif