diff options
| author | gustavo <gustavo> | 1999-08-22 23:31:21 +0000 |
|---|---|---|
| committer | gustavo <gustavo> | 1999-08-22 23:31:21 +0000 |
| commit | 138c7287b24c52ac93f03d177a2d9c5d335d8481 (patch) | |
| tree | 90b0b98936fb5fe862d9f7c56684068a2defa3f8 /src | |
| parent | 1706466f04e464ca53159dfad696d481dca3ec4c (diff) | |
Changed call_timeouts() and Fl::wait()/wait(double). The wait functions will now return immediately (do fl_wait(0,0)) if any timeouts were called in call_timeouts(). Motivation: An event loop like
while (work_to_do) {
work_some();
Fl::check();
} else {
Fl::wait();
}
Suppose that a timeout sets the work_to_do flag, which is initially cleared.
Fl::wait() will wait for this timeout, return, then expire the timeout and wait for user input.
With the fix, it will work as expected.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@669 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl.cxx | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/Fl.cxx b/src/Fl.cxx index 1579d5ac4..efeb063ad 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -1,5 +1,6 @@ +#include <stdio.h> // -// "$Id: Fl.cxx,v 1.24.2.11 1999/07/27 17:24:13 bill Exp $" +// "$Id: Fl.cxx,v 1.24.2.12 1999/08/22 23:31:21 gustavo Exp $" // // Main event handling code for the Fast Light Tool Kit (FLTK). // @@ -111,17 +112,19 @@ void Fl::remove_timeout(void (*cb)(void *), void *v) { numtimeouts = j; } -static void call_timeouts() { +static int call_timeouts() { + int expired = 0; while (numtimeouts) { if (timeout[0].time > 0) break; // we must remove timeout from array before doing the callback: void (*cb)(void*) = timeout[0].cb; void *arg = timeout[0].arg; - numtimeouts--; + numtimeouts--; expired++; if (numtimeouts) memmove(timeout, timeout+1, numtimeouts*sizeof(Timeout)); // now it is safe for the callback to do add_timeout: cb(arg); } + return expired; } void Fl::flush() { @@ -154,7 +157,7 @@ static int initclock; // if false we didn't call fl_elapsed() last time #endif // fl_elapsed must return the amount of time since the last time it was -// called. To reduce the number of system calls the to get the +// called. To reduce the number of system calls to get the // current time, the "initclock" symbol is turned on by an indefinite // wait. This should then reset the measured-from time and return zero static double fl_elapsed() { @@ -204,14 +207,15 @@ static void callidle() { int Fl::wait() { callidle(); - if (numtimeouts) {fl_elapsed(); call_timeouts();} + int expired = 0; + if (numtimeouts) {fl_elapsed(); expired = call_timeouts();} flush(); if (!Fl_X::first) return 0; // no windows - if (idle && !in_idle) + if ((idle && !in_idle) || expired) { fl_wait(1,0.0); - else if (numtimeouts) + } else if (numtimeouts) { fl_wait(1, timeout[0].time); - else { + } else { initclock = 0; fl_wait(0,0); } @@ -220,9 +224,10 @@ int Fl::wait() { double Fl::wait(double time) { callidle(); - if (numtimeouts) {time -= fl_elapsed(); call_timeouts();} + int expired = 0; + if (numtimeouts) {time -= fl_elapsed(); expired = call_timeouts();} flush(); - double wait_time = idle && !in_idle ? 0.0 : time; + double wait_time = (idle && !in_idle) || expired ? 0.0 : time; if (numtimeouts && timeout[0].time < wait_time) wait_time = timeout[0].time; fl_wait(1, wait_time); return time - fl_elapsed(); @@ -695,5 +700,5 @@ int fl_old_shortcut(const char* s) { } // -// End of "$Id: Fl.cxx,v 1.24.2.11 1999/07/27 17:24:13 bill Exp $". +// End of "$Id: Fl.cxx,v 1.24.2.12 1999/08/22 23:31:21 gustavo Exp $". // |
