diff options
| -rw-r--r-- | FL/Fl_System_Driver.H | 5 | ||||
| -rw-r--r-- | src/Fl_lock.cxx | 98 | ||||
| -rw-r--r-- | src/Fl_win32.cxx | 3 | ||||
| -rw-r--r-- | src/drivers/Darwin/Fl_Darwin_System_Driver.H | 5 | ||||
| -rw-r--r-- | src/drivers/Posix/Fl_Posix_System_Driver.H | 5 | ||||
| -rw-r--r-- | src/drivers/WinAPI/Fl_WinAPI_System_Driver.H | 6 |
6 files changed, 97 insertions, 25 deletions
diff --git a/FL/Fl_System_Driver.H b/FL/Fl_System_Driver.H index 0bcc7973b..5441d8185 100644 --- a/FL/Fl_System_Driver.H +++ b/FL/Fl_System_Driver.H @@ -152,6 +152,11 @@ public: virtual void png_extra_rgba_processing(unsigned char *array, int w, int h) {} // the default implementation is most probably enough virtual const char *next_dir_sep(const char *start) { return strchr(start, '/');} + // implement to support threading + virtual void awake(void*) {} + virtual int lock() {return 1;} + virtual void unlock() {} + virtual void* thread_message() {return NULL;} }; #endif // FL_SYSTEM_DRIVER_H diff --git a/src/Fl_lock.cxx b/src/Fl_lock.cxx index 0ec2cf0a5..5cf7a6ff1 100644 --- a/src/Fl_lock.cxx +++ b/src/Fl_lock.cxx @@ -16,12 +16,19 @@ // http://www.fltk.org/str.php // - +#include "config_lib.h" #include <FL/Fl.H> -#include <config.h> #include <stdlib.h> +#if defined(FL_CFG_GFX_QUARTZ) +#include "drivers/Darwin/Fl_Darwin_System_Driver.H" +#elif defined(FL_CFG_GFX_XLIB) +#include "drivers/Posix/Fl_Posix_System_Driver.H" +#elif defined(FL_CFG_SYS_WIN32) +#include "drivers/WinAPI/Fl_WinAPI_System_Driver.H" +#endif + /* From Bill: @@ -137,8 +144,6 @@ int Fl::awake(Fl_Awake_Handler func, void *data) { return ret; } -//////////////////////////////////////////////////////////////// -// Windows threading... /** \fn int Fl::lock() The lock() method blocks the current thread until it can safely access FLTK widgets and data. Child threads should @@ -188,7 +193,9 @@ int Fl::awake(Fl_Awake_Handler func, void *data) { See also: \ref advanced_multithreading */ -#ifdef WIN32 +#if defined(FL_CFG_SYS_WIN32) +//////////////////////////////////////////////////////////////// +// Windows threading... # include <windows.h> # include <process.h> # include <FL/x.H> @@ -232,7 +239,7 @@ static void lock_function() { EnterCriticalSection(&cs); } -int Fl::lock() { +int Fl_WinAPI_System_Driver::lock() { if (!main_thread) InitializeCriticalSection(&cs); lock_function(); @@ -245,17 +252,18 @@ int Fl::lock() { return 0; } -void Fl::unlock() { +void Fl_WinAPI_System_Driver::unlock() { unlock_function(); } -void Fl::awake(void* msg) { +void Fl_WinAPI_System_Driver::awake(void* msg) { PostThreadMessage( main_thread, fl_wake_msg, (WPARAM)msg, 0); } +#endif // FL_CFG_SYS_WIN32 //////////////////////////////////////////////////////////////// // POSIX threading... -#elif defined(HAVE_PTHREAD) +#if defined(HAVE_PTHREAD) # include <unistd.h> # include <fcntl.h> # include <pthread.h> @@ -306,12 +314,12 @@ static void unlock_function_rec() { } # endif // PTHREAD_MUTEX_RECURSIVE -void Fl::awake(void* msg) { +static void posix_awake(void* msg) { if (write(thread_filedes[1], &msg, sizeof(void*))==0) { /* ignore */ } } static void* thread_message_; -void* Fl::thread_message() { +static void* posix_thread_message() { void* r = thread_message_; thread_message_ = 0; return r; @@ -332,7 +340,7 @@ static void thread_awake_cb(int fd, void*) { extern void (*fl_lock_function)(); extern void (*fl_unlock_function)(); -int Fl::lock() { +static int posix_lock() { if (!thread_filedes[1]) { // Initialize thread communication pipe to let threads awake FLTK // from Fl::wait() @@ -370,7 +378,7 @@ int Fl::lock() { return 0; } -void Fl::unlock() { +static void posix_unlock() { fl_unlock_function(); } @@ -389,33 +397,75 @@ void lock_ring() { pthread_mutex_lock(ring_mutex); } -#elif defined(FL_PORTING) +#else -# pragma message "FL_PORTING: implement simple locking and unlocking for basic multithreading support" +static void posix_awake(void*) {} +static int posix_lock() { return 1; } +static void posix_unlock() {} +static void* posix_thread_message() { return NULL; } -#else +#endif // HAVE_PTHREAD -void unlock_ring() { +#if defined(FL_CFG_GFX_QUARTZ) +void Fl_Darwin_System_Driver::awake(void *v) +{ + posix_awake(v); } -void lock_ring() { +int Fl_Darwin_System_Driver::lock() +{ + return posix_lock(); } -void Fl::awake(void*) { +void Fl_Darwin_System_Driver::unlock() +{ + posix_unlock(); } -int Fl::lock() { - return 1; +void* Fl_Darwin_System_Driver::thread_message() +{ + return posix_thread_message(); } +#endif // FL_CFG_GFX_QUARTZ -void Fl::unlock() { +#if defined(FL_CFG_GFX_XLIB) +void Fl_Posix_System_Driver::awake(void *v) +{ + posix_awake(v); +} + +int Fl_Posix_System_Driver::lock() +{ + return posix_lock(); +} + +void Fl_Posix_System_Driver::unlock() +{ + posix_unlock(); +} + +void* Fl_Posix_System_Driver::thread_message() +{ + return posix_thread_message(); +} +#endif // FL_CFG_GFX_XLIB + + +void Fl::awake(void *v) { + Fl::system_driver()->awake(v); } void* Fl::thread_message() { - return NULL; + return Fl::system_driver()->thread_message(); } -#endif // WIN32 +int Fl::lock() { + return Fl::system_driver()->lock(); +} + +void Fl::unlock() { + Fl::system_driver()->unlock(); +} // // End of "$Id$". diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx index 33addd3f2..02cf80637 100644 --- a/src/Fl_win32.cxx +++ b/src/Fl_win32.cxx @@ -54,6 +54,7 @@ void fl_cleanup_dc_list(void); #include <FL/Fl_Screen_Driver.H> #include <FL/Fl_Graphics_Driver.H> // for fl_graphics_driver #include "drivers/WinAPI/Fl_WinAPI_Window_Driver.H" +#include "drivers/WinAPI/Fl_WinAPI_System_Driver.H" #include <FL/fl_utf8.h> #include <FL/Fl_Window.H> #include <FL/fl_draw.H> @@ -371,7 +372,7 @@ void (*fl_lock_function)() = nothing; void (*fl_unlock_function)() = nothing; static void* thread_message_; -void* Fl::thread_message() { +void* Fl_WinAPI_System_Driver::thread_message() { void* r = thread_message_; thread_message_ = 0; return r; diff --git a/src/drivers/Darwin/Fl_Darwin_System_Driver.H b/src/drivers/Darwin/Fl_Darwin_System_Driver.H index df7705008..31b8e4564 100644 --- a/src/drivers/Darwin/Fl_Darwin_System_Driver.H +++ b/src/drivers/Darwin/Fl_Darwin_System_Driver.H @@ -80,6 +80,11 @@ public: virtual char *preference_rootnode(Fl_Preferences *prefs, Fl_Preferences::Root root, const char *vendor, const char *application); virtual void *dlopen(const char *filename); + // these 4 are implemented in Fl_lock.cxx + virtual void awake(void*); + virtual int lock(); + virtual void unlock(); + virtual void* thread_message(); }; #endif // FL_DARWIN_SYSTEM_DRIVER_H diff --git a/src/drivers/Posix/Fl_Posix_System_Driver.H b/src/drivers/Posix/Fl_Posix_System_Driver.H index 549729651..67f060b04 100644 --- a/src/drivers/Posix/Fl_Posix_System_Driver.H +++ b/src/drivers/Posix/Fl_Posix_System_Driver.H @@ -81,6 +81,11 @@ public: const char *application); virtual int preferences_need_protection_check() {return 1;} virtual void *dlopen(const char *filename); + // these 4 are implemented in Fl_lock.cxx + virtual void awake(void*); + virtual int lock(); + virtual void unlock(); + virtual void* thread_message(); }; #endif // FL_POSIX_SYSTEM_DRIVER_H diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H index 49fb1da63..cbec9065d 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H +++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H @@ -86,6 +86,12 @@ public: virtual void *dlopen(const char *filename); virtual void png_extra_rgba_processing(unsigned char *array, int w, int h); virtual const char *next_dir_sep(const char *start); + // these 3 are implemented in Fl_lock.cxx + virtual void awake(void*); + virtual int lock(); + virtual void unlock(); + // this one is implemented in Fl_win32.cxx + virtual void* thread_message(); }; #endif // FL_WINAPI_SYSTEM_DRIVER_H |
