Skip to content

Commit

Permalink
In TaskPipelineManager, a new kTaskPipelineStatusTerminating status c…
Browse files Browse the repository at this point in the history
…ode was added between the kTaskPipelineStatusRunning and kTaskPipelineStatusTerminated phases.

In TaskPipelineManager terminateTasks, the @synchronized directive was used in a critical section of code, and the result of NSTask isRunning is checked before sending the terminate message.  This should avoid some crashes that occurred when terminate was sent to an NSTask that had already terminated.

Also, the NSTask terminate section of code is now enclosed in a @try/@catch block to avoid app crashes.
  • Loading branch information
dsward2 authored and dsward2 committed Dec 29, 2017
1 parent d704152 commit 2b4b6e0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions LocalRadio/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.12</string>
<string>1.13</string>
<key>CFBundleVersion</key>
<string>13</string>
<string>14</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.entertainment</string>
<key>LSMinimumSystemVersion</key>
Expand Down
3 changes: 2 additions & 1 deletion LocalRadio/TaskPipelineManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

#define kTaskPipelineStatusIdle 0
#define kTaskPipelineStatusRunning 1
#define kTaskPipelineStatusTerminated 2
#define kTaskPipelineStatusTerminating 2
#define kTaskPipelineStatusTerminated 3

@class TaskItem;

Expand Down
31 changes: 19 additions & 12 deletions LocalRadio/TaskPipelineManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ - (void) startTasks

[self configureTaskPipes];

//NSArray * reversedTaskItemsArray = [[self.taskItemsArray reverseObjectEnumerator] allObjects];

//for (TaskItem * taskItem in reversedTaskItemsArray)
for (TaskItem * taskItem in self.taskItemsArray)
{
NSError * startTaskError = [taskItem startTask];
Expand All @@ -136,19 +133,29 @@ - (void) startTasks

- (void) terminateTasks
{
//NSArray * reversedTaskItemsArray = [[self.taskItemsArray reverseObjectEnumerator] allObjects];

//for (TaskItem * taskItem in reversedTaskItemsArray)
for (TaskItem * taskItem in self.taskItemsArray)
@synchronized (self)
{
NSError * terminateTaskError = [taskItem terminateTask];
}

[self.taskItemsArray removeAllObjects];
self.taskPipelineStatus = kTaskPipelineStatusTerminating;

self.taskPipelineStatus = kTaskPipelineStatusTerminated;
for (TaskItem * taskItem in self.taskItemsArray)
{
if (taskItem.task.isRunning == YES)
{
@try {
NSError * terminateTaskError = [taskItem terminateTask];
}
@catch (NSException *exception) {

}
}
}

[self.taskItemsArray removeAllObjects];
}

[NSThread sleepForTimeInterval:0.1f];

self.taskPipelineStatus = kTaskPipelineStatusTerminated;
}


Expand Down

0 comments on commit 2b4b6e0

Please sign in to comment.