-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
main.m
41 lines (32 loc) · 1.19 KB
/
main.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
41
#import "Launcher.h"
#define FOREVER ((CFTimeInterval) 1e20)
static void timer_empty(CFRunLoopTimerRef timer, void *info) {
}
static void parkRunLoop() {
CFRunLoopTimerRef t = CFRunLoopTimerCreate(kCFAllocatorDefault, FOREVER, (CFTimeInterval)0.0, 0, 0, timer_empty, NULL);
CFRunLoopAddTimer(CFRunLoopGetCurrent(), t, kCFRunLoopDefaultMode);
CFRelease(t);
SInt32 result;
do {
result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, FOREVER, false);
} while (result != kCFRunLoopRunFinished);
}
static void makeSameStackSize(NSThread *thread) {
struct rlimit l;
int err = getrlimit(RLIMIT_STACK, &l);
if (err == ERR_SUCCESS && l.rlim_cur > 0) {
thread.stackSize = (NSUInteger) l.rlim_cur;
}
}
static void launchInNewThread(Launcher *launcher) {
NSThread *thread = [[[NSThread alloc] initWithTarget:launcher selector:@selector(launch) object:nil] autorelease];
makeSameStackSize(thread);
[thread start];
}
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
launchInNewThread([[[Launcher alloc] initWithArgc:argc argv:argv] autorelease]);
parkRunLoop();
[pool release];
return 0;
}