From 2fcd3610d57dacb6d4836991f05ea9728929c10d Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Sun, 28 Jan 2007 20:03:31 +0000 Subject: [PATCH] Fl::awake() could block on X11 and OSX (STR #1537) git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@5646 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- CHANGES | 1 + src/Fl_lock.cxx | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 2f4fbcf60..bc7889ec2 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,6 @@ CHANGES IN FLTK 1.1.8 + - Fl::awake() could block on X11 and OSX (STR #1537) - WIN32 did check callbacks after the event processing instead of before as documented (STR #1535) - Fl_File_Chooser now hides the window before doing a callback diff --git a/src/Fl_lock.cxx b/src/Fl_lock.cxx index 895e78021..6f3b44f2c 100644 --- a/src/Fl_lock.cxx +++ b/src/Fl_lock.cxx @@ -127,9 +127,10 @@ void Fl::awake(void* msg) { // POSIX threading... #elif HAVE_PTHREAD # include +# include # include -# if defined (PTHREAD_MUTEX_RECURSIVE_NP) +# ifdef PTHREAD_MUTEX_RECURSIVE_NP // Linux supports recursive locks, use them directly: static bool minit; @@ -149,7 +150,7 @@ void Fl::unlock() { pthread_mutex_unlock(&fltk_mutex); } -# else +# else // !PTHREAD_MUTEX_RECURSIVE_NP // Make a recursive lock out of the pthread mutex: static pthread_mutex_t fltk_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -168,7 +169,7 @@ void Fl::unlock() { if (!--counter) pthread_mutex_unlock(&fltk_mutex); } -# endif +# endif // PTHREAD_MUTEX_RECURSIVE_NP // Pipe for thread messaging... static int thread_filedes[2]; @@ -193,6 +194,8 @@ void Fl::lock() { if (!thread_filedes[1]) { // initialize the mt support // Init threads communication pipe to let threads awake FLTK from wait pipe(thread_filedes); + fcntl(thread_filedes[1], F_SETFL, + fcntl(thread_filedes[1], F_GETFL) | O_NONBLOCK); Fl::add_fd(thread_filedes[0], FL_READ, thread_awake_cb); fl_lock_function = lock_function; fl_unlock_function = Fl::unlock; @@ -203,7 +206,7 @@ void Fl::awake(void* msg) { write(thread_filedes[1], &msg, sizeof(void*)); } -#endif +#endif // WIN32 // // End of "$Id$".