summaryrefslogtreecommitdiff
path: root/src/Fl_lock.cxx
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2011-02-06 19:46:11 +0000
committerManolo Gouy <Manolo>2011-02-06 19:46:11 +0000
commitdc8edfc2169b2744b1de237e0ecafd83ff8299c3 (patch)
tree52ce7188310a5738289550c05a3b1c86d6590f4b /src/Fl_lock.cxx
parent75dea1bd8d732f15706f3473b52db24fdb7bed50 (diff)
Fix for STR #2543: Fl::lock() function now returns an int that allows to detect whether
threading is available on the platform. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8393 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_lock.cxx')
-rw-r--r--src/Fl_lock.cxx45
1 files changed, 30 insertions, 15 deletions
diff --git a/src/Fl_lock.cxx b/src/Fl_lock.cxx
index c5c0cd94a..4328be8c3 100644
--- a/src/Fl_lock.cxx
+++ b/src/Fl_lock.cxx
@@ -121,11 +121,15 @@ int Fl::get_awake_handler_(Fl_Awake_Handler &func, void *&data)
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 @@ int Fl::awake(Fl_Awake_Handler func, void *data) {
////////////////////////////////////////////////////////////////
// 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 @@ int Fl::awake(Fl_Awake_Handler func, void *data) {
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 @@ int Fl::awake(Fl_Awake_Handler func, void *data) {
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 @@ int Fl::awake(Fl_Awake_Handler func, void *data) {
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 @@ static void lock_function() {
EnterCriticalSection(&cs);
}
-void Fl::lock() {
+int Fl::lock() {
if (!main_thread) InitializeCriticalSection(&cs);
lock_function();
@@ -240,6 +242,7 @@ void Fl::lock() {
fl_unlock_function = unlock_function;
main_thread = GetCurrentThreadId();
}
+ return 0;
}
void Fl::unlock() {
@@ -329,7 +332,7 @@ static void thread_awake_cb(int fd, void*) {
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 @@ void Fl::lock() {
}
fl_lock_function();
+ return 0;
}
void Fl::unlock() {
@@ -396,6 +400,17 @@ void lock_ring() {
void Fl::awake(void*) {
}
+int Fl::lock() {
+ return 1;
+}
+
+void Fl::unlock() {
+}
+
+void* Fl::thread_message() {
+ return NULL;
+}
+
#endif // WIN32
//