forked from gnachman/iTerm2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBackgroundThread.m
40 lines (34 loc) · 863 Bytes
/
BackgroundThread.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// BackgroundThread.m
// iTerm
//
// Created by George Nachman on 3/1/12.
//
#import "BackgroundThread.h"
@implementation BackgroundThread
+ (NSThread *)backgroundThread
{
static NSThread *thread;
if (!thread) {
thread = [[BackgroundThread alloc] init];
[thread start];
}
return thread;
}
- (void)main
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSRunLoop* myRunLoop = [NSRunLoop currentRunLoop];
// This keeps the runloop blocking when nothing else is going on.
[myRunLoop addPort:[NSMachPort port]
forMode:NSDefaultRunLoopMode];
while (1) {
if (!pool) {
pool = [[NSAutoreleasePool alloc] init];
}
[myRunLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
[pool drain];
pool = nil;
}
}
@end