Skip to content
Snippets Groups Projects
Commit 7bd18b7e authored by George Nachman's avatar George Nachman
Browse files

Make some changes to try to fix a common crash in setFastTimer when it's...

Make some changes to try to fix a common crash in setFastTimer when it's called from a notification when we become key
parent 2a9e1e48
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -20,6 +20,7 @@
NSMutableArray *pids_;
BOOL hasSelection;
BOOL shutdown_;
NSTimeInterval timerInterval_;
}
 
@property (nonatomic, assign) BOOL hasSelection;
Loading
Loading
Loading
Loading
@@ -102,15 +102,11 @@ static const CGFloat kMargin = 4;
[scrollView_ setDocumentView:tableView_];
[self addSubview:scrollView_];
[tableView_ sizeToFit];
[tableView_ setColumnAutoresizingStyle:NSTableViewSequentialColumnAutoresizingStyle];
 
timer_ = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(updateTimer:)
userInfo:nil
repeats:YES];
timerInterval_ = 1;
 
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(setSlowTimer)
Loading
Loading
@@ -140,23 +136,15 @@ static const CGFloat kMargin = 4;
// When not key, check much less often to avoid burning the battery.
- (void)setSlowTimer
{
[timer_ invalidate];
timer_ = [NSTimer scheduledTimerWithTimeInterval:10
target:self
selector:@selector(updateTimer:)
userInfo:nil
repeats:YES];
timerInterval_ = 10;
}
 
- (void)setFastTimer
{
[self updateTimer:nil];
timerInterval_ = 1;
[timer_ invalidate];
timer_ = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(updateTimer:)
userInfo:nil
repeats:YES];
timer_ = nil;
[self updateTimer:nil];
}
 
- (void)dealloc
Loading
Loading
@@ -166,6 +154,7 @@ static const CGFloat kMargin = 4;
[tableView_ release];
[scrollView_ release];
[timer_ invalidate];
timer_ = nil;
[names_ release];
[pids_ release];
[super dealloc];
Loading
Loading
@@ -176,43 +165,48 @@ static const CGFloat kMargin = 4;
[[NSNotificationCenter defaultCenter] removeObserver:self];
shutdown_ = YES;
[timer_ invalidate];
[kill_ unbind:@"enabled"];
timer_ = nil;
[kill_ unbind:@"enabled"];
}
 
- (void)updateTimer:(id)sender
{
timer_ = nil;
if (shutdown_) {
return;
}
ToolWrapper *wrapper = (ToolWrapper *)[[self superview] superview];
pid_t rootPid = [[[wrapper.term currentSession] SHELL] pid];
NSSet *pids = [[ProcessCache sharedInstance] childrenOfPid:rootPid levelsToSkip:0];
if ([pids isEqualToSet:[NSSet setWithArray:pids_]]) {
// Nothing to do, skip the expensive step of getting names.
return;
}
[pids_ release];
pids_ = [[[pids allObjects] sortedArrayUsingSelector:@selector(compare:)] retain];
[names_ removeAllObjects];
int i = 0;
for (NSNumber *pid in pids_) {
BOOL fg;
NSString *pidName;
pidName = [[ProcessCache sharedInstance] getNameOfPid:[pid intValue]
isForeground:&fg];
if (pidName) {
[names_ addObject:pidName];
i++;
if (i > kMaxJobs) {
break;
if (![pids isEqualToSet:[NSSet setWithArray:pids_]]) {
// Something changed. Get job names, which is expensive.
[pids_ release];
pids_ = [[[pids allObjects] sortedArrayUsingSelector:@selector(compare:)] retain];
[names_ removeAllObjects];
int i = 0;
for (NSNumber *pid in pids_) {
BOOL fg;
NSString *pidName;
pidName = [[ProcessCache sharedInstance] getNameOfPid:[pid intValue]
isForeground:&fg];
if (pidName) {
[names_ addObject:pidName];
i++;
if (i > kMaxJobs) {
break;
}
}
}
}
[tableView_ reloadData];
[tableView_ reloadData];
 
// Updating the table data causes the cursor to change into an arrow!
[self performSelector:@selector(fixCursor) withObject:nil afterDelay:0];
// Updating the table data causes the cursor to change into an arrow!
[self performSelector:@selector(fixCursor) withObject:nil afterDelay:0];
}
timer_ = [NSTimer scheduledTimerWithTimeInterval:timerInterval_
target:self
selector:@selector(updateTimer:)
userInfo:nil
repeats:NO];
}
 
- (void)fixCursor
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment