summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2017-06-26 15:20:25 +0000
committerManolo Gouy <Manolo>2017-06-26 15:20:25 +0000
commit66200436bff3b1730d50490ad68ee6e945a16b88 (patch)
treecb143d43d85dce843b50044a54c77fd03fe2807e /src
parent51ed4e2162d4630c19da3d95ce689e59a8ca7b3c (diff)
Fix for STR#3387 Bug of timer implementation on macosx
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12271 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_cocoa.mm30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index 743f0c5a1..66184cc4d 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -505,7 +505,7 @@ struct MacTimeout {
static MacTimeout* mac_timers;
static int mac_timer_alloc;
static int mac_timer_used;
-static MacTimeout* current_timer; // the timer that triggered its callback function, or NULL
+static MacTimeout* current_timer; // the timer that triggered its callback function
static void realloc_timers()
{
@@ -530,14 +530,14 @@ static void delete_timer(MacTimeout& t)
kCFRunLoopDefaultMode);
CFRelease(t.timer);
memset(&t, 0, sizeof(MacTimeout));
- if (&t == current_timer) current_timer = NULL;
}
}
static void do_timer(CFRunLoopTimerRef timer, void* data)
{
fl_lock_function();
- current_timer = (MacTimeout*)data;
+ fl_intptr_t timerId = (fl_intptr_t)data;
+ current_timer = &mac_timers[timerId];
current_timer->pending = 0;
(current_timer->callback)(current_timer->data);
if (current_timer && current_timer->pending == 0)
@@ -562,7 +562,7 @@ void Fl_Cocoa_Screen_Driver::add_timeout(double time, Fl_Timeout_Handler cb, voi
}
}
// no existing timer to use. Create a new one:
- int timer_id = -1;
+ fl_intptr_t timer_id = -1;
// find an empty slot in the timer array
for (int i = 0; i < mac_timer_used; ++i) {
if ( !mac_timers[i].timer ) {
@@ -580,7 +580,7 @@ void Fl_Cocoa_Screen_Driver::add_timeout(double time, Fl_Timeout_Handler cb, voi
}
// now install a brand new timer
MacTimeout& t = mac_timers[timer_id];
- CFRunLoopTimerContext context = {0, &t, NULL,NULL,NULL};
+ CFRunLoopTimerContext context = {0, (void*)timer_id, NULL,NULL,NULL};
CFRunLoopTimerRef timerRef = CFRunLoopTimerCreate(kCFAllocatorDefault,
CFAbsoluteTimeGetCurrent() + time,
1E30,
@@ -603,18 +603,14 @@ void Fl_Cocoa_Screen_Driver::add_timeout(double time, Fl_Timeout_Handler cb, voi
void Fl_Cocoa_Screen_Driver::repeat_timeout(double time, Fl_Timeout_Handler cb, void* data)
{
- if (current_timer) {
- // k = how many times 'time' seconds after the last scheduled timeout until the future
- double k = ceil( (CFAbsoluteTimeGetCurrent() - current_timer->next_timeout) / time);
- if (k < 1) k = 1;
- current_timer->next_timeout += k * time;
- CFRunLoopTimerSetNextFireDate(current_timer->timer, current_timer->next_timeout );
- current_timer->callback = cb;
- current_timer->data = data;
- current_timer->pending = 1;
- return;
- }
- add_timeout(time, cb, data);
+ // k = how many times 'time' seconds after the last scheduled timeout until the future
+ double k = ceil( (CFAbsoluteTimeGetCurrent() - current_timer->next_timeout) / time);
+ if (k < 1) k = 1;
+ current_timer->next_timeout += k * time;
+ CFRunLoopTimerSetNextFireDate(current_timer->timer, current_timer->next_timeout );
+ current_timer->callback = cb;
+ current_timer->data = data;
+ current_timer->pending = 1;
}
int Fl_Cocoa_Screen_Driver::has_timeout(Fl_Timeout_Handler cb, void* data)