diff --git a/Source/CFRunLoop.c b/Source/CFRunLoop.c index 88a4ad2..f148b0e 100644 --- a/Source/CFRunLoop.c +++ b/Source/CFRunLoop.c @@ -1845,8 +1845,8 @@ CFRunLoopTimerSetNextFireDate (CFRunLoopTimerRef timer, } timer->_nextFireDate = fireDate; - // Wake up the runloop so that it can recalculate the next timer date - // but since timers should be planned on current runloop only (NSTimer - // says so), this may not be necessary. - CFRunLoopWakeUp(timer->_runloop); + // Wake up the runloop so that it can recalculate the next timer date, + // but only if the timer has been added to one. + if (timer->_runloop != NULL) + CFRunLoopWakeUp(timer->_runloop); } diff --git a/Tests/CFRunLoop/timer_setfiredate.m b/Tests/CFRunLoop/timer_setfiredate.m new file mode 100644 index 0000000..32d869d --- /dev/null +++ b/Tests/CFRunLoop/timer_setfiredate.m @@ -0,0 +1,20 @@ +#include "CoreFoundation/CFRunLoop.h" +#include "../CFTesting.h" + +static void +fire (CFRunLoopTimerRef t, void *info) +{ +} + +int main (void) +{ + CFRunLoopTimerRef t = CFRunLoopTimerCreate (NULL, 100.0, 5.0, 0, 0, + fire, NULL); + + CFRunLoopTimerSetNextFireDate (t, 250.0); + PASS_CF (CFRunLoopTimerGetNextFireDate (t) == 250.0, + "Setting the fire date of a timer not in a run loop updates it."); + + CFRelease (t); + return 0; +}