From 6e9a1630357a21c6ef6357cdde324ae89a565826 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Thu, 8 Feb 2007 23:04:20 +0000 Subject: Add handler for thread messages (STR #1536) git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@5683 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_lock.cxx | 14 ++++++++++++++ src/Fl_win32.cxx | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Fl_lock.cxx b/src/Fl_lock.cxx index be52f78d1..31206c8e7 100644 --- a/src/Fl_lock.cxx +++ b/src/Fl_lock.cxx @@ -38,6 +38,14 @@ another. This file is an attempt to make minimal additions and make them self-contained in this source file. + From Mike: + + Starting with 1.1.8, we now have a callback so that you can + process awake() messages as they come in. + + + The API: + Fl::lock() - recursive lock. You must call this before the first call to Fl::wait()/run() to initialize the thread system. The lock is locked all the time except when @@ -48,12 +56,17 @@ Fl::awake(void*) - Causes Fl::wait() to return (with the lock locked) even if there are no events ready. + Fl::set_awake_cb(void (*cb)(void *)) - Registers a function + to call for Fl::awake() messages that is called for each + message received. + Fl::thread_message() - returns an argument sent to an Fl::awake() call, or returns NULL if none. WARNING: the current implementation only has a one-entry queue and only returns the most recent value! */ +void (*Fl::awake_cb)(void *); //////////////////////////////////////////////////////////////// // Windows threading... @@ -189,6 +202,7 @@ void* Fl::thread_message() { static void thread_awake_cb(int fd, void*) { read(fd, &thread_message_, sizeof(void*)); + if (Fl::awake_cb) (*Fl::awake_cb)(thread_message_); } // These pointers are in Fl_x.cxx: diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx index 632c6cb42..a4660def8 100644 --- a/src/Fl_win32.cxx +++ b/src/Fl_win32.cxx @@ -291,8 +291,11 @@ int fl_wait(double time_to_wait) { } #endif - if (fl_msg.message == fl_wake_msg) // Used for awaking wait() from another thread + if (fl_msg.message == fl_wake_msg) { + // Used for awaking wait() from another thread thread_message_ = (void*)fl_msg.wParam; + if (awake_cb) (*awake_cb)(thread_message_); + } TranslateMessage(&fl_msg); DispatchMessage(&fl_msg); -- cgit v1.2.3