diff options
| author | Manolo Gouy <Manolo> | 2016-04-10 20:38:04 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2016-04-10 20:38:04 +0000 |
| commit | 6879d54fc494dd07c214c8582806304e6b09e80f (patch) | |
| tree | 984836e446f9d7d7f5618f2761bfef75bb88722a /src/Fl_lock.cxx | |
| parent | 95fa60b71dceadffd65f8f135a89efb05a8d6fd7 (diff) | |
Rewrite Fl_lock.cxx under the driver model.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11578 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_lock.cxx')
| -rw-r--r-- | src/Fl_lock.cxx | 98 |
1 files changed, 74 insertions, 24 deletions
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$". |
