-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Investigation: timers synchronization #33
base: master
Are you sure you want to change the base?
Changes from 1 commit
d5de41e
129ed8c
d3c2af4
2100b7b
b5677c7
716e2a7
a4aa2d5
ef92890
8b9d012
ee5c6a0
f2b47c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,47 +112,24 @@ - (void)setDisplayLink:(CADisplayLink*)displayLink | |
#endif | ||
} | ||
|
||
- (void)fire:(id)timer | ||
- (void)fire | ||
{ | ||
//This is to ensure the timer is still valid after fire. | ||
CFRunLoopRef runloop = CFRunLoopGetCurrent(); | ||
CFRunLoopMode mode = CFRunLoopCopyCurrentMode(runloop); | ||
CFRunLoopPerformBlock(runloop, mode, ^{ | ||
if(CFRunLoopTimerIsValid((__bridge CFRunLoopTimerRef)timer) == NO) | ||
{ | ||
[self untrack]; | ||
|
||
CFRelease(mode); | ||
|
||
return; | ||
} | ||
|
||
CFRunLoopPerformBlock(runloop, mode, ^{ | ||
if(CFRunLoopTimerIsValid((__bridge CFRunLoopTimerRef)timer) == NO) | ||
{ | ||
[self untrack]; | ||
|
||
CFRelease(mode); | ||
|
||
return; | ||
} | ||
|
||
CFRelease(mode); | ||
}); | ||
}); | ||
Comment on lines
-117
to
-142
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand right, the purpose of these are to see if the timer is still valid after it has fired. If we ask if the timer is valid inline here, Here I'm proposing a different method. We track the invalidation and removal of timers (in NSTimer+DTXSpy.m), which means we know when a repeating timer is stopping. We also know that a timer that doesn't repeat is finished once we have called its callback (or selector). Therefore, we can simply call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I understand, this code checks whether the timer needs to be untracked (for example, as you mentioned - in case of a non-repeating timer) immediately after finishing the fire.
Generally, this sounds right, but I'm not sure if recurring / non-recurring is our only flow. What about calling to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling |
||
|
||
if(_callback) | ||
{ | ||
CFRunLoopTimerContext ctx; | ||
CFRunLoopTimerGetContext((__bridge CFRunLoopTimerRef)timer, &ctx); | ||
_callback((__bridge CFRunLoopTimerRef)timer, ctx.info); | ||
return; | ||
CFRunLoopTimerGetContext((__bridge CFRunLoopTimerRef)_timer, &ctx); | ||
_callback((__bridge CFRunLoopTimerRef)_timer, ctx.info); | ||
} | ||
|
||
if(_target && _sel) { | ||
IMP impl = [_target methodForSelector:_sel]; | ||
void (*func)(id, SEL, NSTimer*) = (void *)impl; | ||
func(_target, _sel, _timer); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a small tidy-up recommended by https://stackoverflow.com/a/20058585 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
if(!_repeats) { | ||
[self untrack]; | ||
} | ||
Comment on lines
+141
to
143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this will have the same result as the previous check. |
||
|
||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Warc-performSelector-leaks" | ||
[_target performSelector:_sel withObject:timer]; | ||
#pragma clang diagnostic pop | ||
Comment on lines
-152
to
-155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did you removed this? I guess it was there for a reason There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is replaced by ln 131-138 - gaining a reference to I think my previous comment was lost - sorry. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It wasn't, you're right #33 (comment), forgot about this for a moment 😅 |
||
} | ||
|
||
- (void)track | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following changes are a bit more involved.
Firstly, there's no need for the
timer
parameter - we already have a reference to that as an ivar.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can understand why the
timer
argument is redundant.