Author: manolo
Date: 2011-02-06 11:46:11 -0800 (Sun, 06 Feb 2011)
New Revision: 8393
Log:
Fix for STR #2543: Fl::lock() function now returns an int that allows to detect
whether
threading is available on the platform.
Modified:
branches/branch-1.3/FL/Fl.H
branches/branch-1.3/src/Fl_lock.cxx
Modified: branches/branch-1.3/FL/Fl.H
===================================================================
--- branches/branch-1.3/FL/Fl.H 2011-02-06 14:48:36 UTC (rev 8392)
+++ branches/branch-1.3/FL/Fl.H 2011-02-06 19:46:11 UTC (rev 8393)
@@ -979,7 +979,7 @@
@{ */
// Multithreading support:
- static void lock();
+ static int lock();
static void unlock();
static void awake(void* message = 0);
/** See void awake(void* message=0). */
Modified: branches/branch-1.3/src/Fl_lock.cxx
===================================================================
--- branches/branch-1.3/src/Fl_lock.cxx 2011-02-06 14:48:36 UTC (rev 8392)
+++ branches/branch-1.3/src/Fl_lock.cxx 2011-02-06 19:46:11 UTC (rev 8393)
@@ -121,11 +121,15 @@
return ret;
}
-//
/**
- Let the main thread know an update is pending
- and have it call a specific function
- See void awake(void* message=0).
+ Let the main thread know an update is pending and have it call a specific
function.
+ Registers a function that will be
+ called by the main thread during the next message handling cycle.
+ Returns 0 if the callback function was registered,
+ and -1 if registration failed. Over a thousand awake callbacks can be
+ registered simultaneously.
+
+ \see Fl::awake(void* message=0)
*/
int Fl::awake(Fl_Awake_Handler func, void *data) {
int ret = add_awake_handler_(func, data);
@@ -135,12 +139,13 @@
////////////////////////////////////////////////////////////////
// Windows threading...
-/** \fn void Fl::lock()
+/** \fn int Fl::lock()
The lock() method blocks the current thread until it
can safely access FLTK widgets and data. Child threads should
call this method prior to updating any widgets or accessing
data. The main thread must call lock() to initialize
- the threading support in FLTK.
+ the threading support in FLTK. lock() will return non-zero
+ if threading is not available on the platform.
Child threads must call unlock() when they are done
accessing FLTK.
@@ -150,6 +155,9 @@
Similarly, when the main thread needs to do processing, it will
wait until all child threads have called unlock() before processing
additional data.
+
+ \return 0 if threading is available on the platform; non-zero
+ otherwise.
See also: \ref advanced_multithreading
*/
@@ -162,7 +170,7 @@
See also: \ref advanced_multithreading
*/
/** \fn void Fl::awake(void* msg)
- The awake() method sends a message pointer to the main thread,
+ Sends a message pointer to the main thread,
causing any pending Fl::wait() call to
terminate so that the main thread can retrieve the message and any pending
redraws can be processed.
@@ -172,12 +180,6 @@
thousand) depth. The default message handler saves the last message which
can be accessed using the
Fl::thread_message() function.
-
- The second form of awake() registers a function that will be
- called by the main thread during the next message handling cycle.
- awake() will return 0 if the callback function was registered,
- and -1 if registration failed. Over a thousand awake callbacks can be
- registered simultaneously.
In the context of a threaded application, a call to Fl::awake() with no
argument will trigger event loop handling in the main thread. Since
@@ -230,7 +232,7 @@
EnterCriticalSection(&cs);
}
-void Fl::lock() {
+int Fl::lock() {
if (!main_thread) InitializeCriticalSection(&cs);
lock_function();
@@ -240,6 +242,7 @@
fl_unlock_function = unlock_function;
main_thread = GetCurrentThreadId();
}
+ return 0;
}
void Fl::unlock() {
@@ -329,7 +332,7 @@
extern void (*fl_lock_function)();
extern void (*fl_unlock_function)();
-void Fl::lock() {
+int Fl::lock() {
if (!thread_filedes[1]) {
// Initialize thread communication pipe to let threads awake FLTK
// from Fl::wait()
@@ -364,6 +367,7 @@
}
fl_lock_function();
+ return 0;
}
void Fl::unlock() {
@@ -396,6 +400,17 @@
void Fl::awake(void*) {
}
+int Fl::lock() {
+ return 1;
+}
+
+void Fl::unlock() {
+}
+
+void* Fl::thread_message() {
+ return NULL;
+}
+
#endif // WIN32
//
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit