@@ -14,10 +14,12 @@ * file. */ #include "config.h" +#include + #import "OFTimer.h" #import "OFDate.h" #import "OFRunLoop.h" #import "OFCondition.h" @@ -313,10 +315,16 @@ } #endif - (void)dealloc { + /* + * The run loop references the timer, so it should never be deallocated + * if it is still in a run loop. + */ + assert(inRunLoop == nil); + [fireDate release]; [target release]; [object1 release]; [object2 release]; #ifdef OF_HAVE_BLOCKS @@ -389,10 +397,26 @@ - (OFDate*)fireDate { OF_GETTER(fireDate, YES) } + +- (void)setFireDate: (OFDate*)fireDate_ +{ + [self retain]; + @try { + @synchronized (self) { + [inRunLoop OF_removeTimer: self]; + + OF_SETTER(fireDate, fireDate_, YES, 0) + + [inRunLoop addTimer: self]; + } + } @finally { + [self release]; + } +} - (double)timeInterval { return interval; } @@ -419,6 +443,11 @@ [condition wait]; } @finally { [condition unlock]; } } + +- (void)OF_setInRunLoop: (OFRunLoop*)inRunLoop_ +{ + OF_SETTER(inRunLoop, inRunLoop_, YES, 0) +} @end