Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 58 lines (45 sloc) 2.036 kB
dc5be1c Initial check-in.
uli authored
1 //
2 // NSTask+UKAsyncBackgroundProcessing.m
3 // AngelBzr
4 //
5 // Created by Uli Kusterer on 31.05.08.
720b0e7 @uliwitness Added licensing information to the source files.
authored
6 // Copyright 2008 Uli Kusterer.
7 //
8 // This software is provided 'as-is', without any express or implied
9 // warranty. In no event will the authors be held liable for any damages
10 // arising from the use of this software.
11 //
12 // Permission is granted to anyone to use this software for any purpose,
13 // including commercial applications, and to alter it and redistribute it
14 // freely, subject to the following restrictions:
15 //
16 // 1. The origin of this software must not be misrepresented; you must not
17 // claim that you wrote the original software. If you use this software
18 // in a product, an acknowledgment in the product documentation would be
19 // appreciated but is not required.
20 //
21 // 2. Altered source versions must be plainly marked as such, and must not be
22 // misrepresented as being the original software.
23 //
24 // 3. This notice may not be removed or altered from any source
25 // distribution.
dc5be1c Initial check-in.
uli authored
26 //
27
28 #import "NSTask+UKAsyncBackgroundProcessing.h"
29
30
31 @implementation NSTask (UKAsyncBackgroundProcessing)
32
33 -(void) threadedWaitUntilExitTakingOverInfoArray: (NSArray*)infoArray
34 {
35 // This method takes over the array it gets to avoid dangling pointers due to race conditions.
36 SEL didEndSelector = [[infoArray objectAtIndex: 1] pointerValue];
37 id didEndTarget = [infoArray objectAtIndex: 0];
38
39 [self waitUntilExit];
40
41 [didEndTarget performSelectorOnMainThread: didEndSelector withObject: self waitUntilDone: YES];
42
43 [infoArray release];
44 }
45
46
47 -(void) waitUntilExitAsynchronouslyWithTarget: (id)targ finishSelector: (SEL)fini
48 {
49 NSArray* info = [[NSArray alloc] initWithObjects: targ, [NSValue valueWithPointer: fini], nil];
50 // Array is alloced by us, released by the child thread, otherwise we might release it while the
51 // other thread is swapped out and hasnt retained it yet.
52
53 [NSThread detachNewThreadSelector: @selector(threadedWaitUntilExitTakingOverInfoArray:) toTarget: self withObject: info];
54 }
55
56
57 @end
Something went wrong with that request. Please try again.