|
@@ -78,7 +78,7 @@ void *thread_entry(void* argument);
|
|
|
param.sched_priority = sched_get_priority_max(SCHED_FIFO);
|
|
|
pthread_attr_setschedparam(&attr, ¶m);
|
|
|
pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
|
|
|
- pthread_create(&thread, &attr, thread_entry, (void*)self);
|
|
|
+ pthread_create(&thread, &attr, thread_entry, (void*)CFBridgingRetain(self));
|
|
|
|
|
|
return self;
|
|
|
}
|
|
@@ -127,7 +127,7 @@ void *thread_entry(void* argument);
|
|
|
#if NS_BLOCKS_AVAILABLE
|
|
|
- (void)scheduleBlock:(void (^)(void))block inTimeInterval:(NSTimeInterval)timeInterval {
|
|
|
[self addSchedule:[NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
- [[block copy] autorelease], kBlockKey,
|
|
|
+ [block copy], kBlockKey,
|
|
|
[NSNumber numberWithUnsignedLongLong:mach_absolute_time() + (timeInterval / timebase_ratio)], kTimeKey,
|
|
|
nil]];
|
|
|
}
|
|
@@ -146,7 +146,7 @@ void *thread_entry(void* argument);
|
|
|
}
|
|
|
|
|
|
void *thread_entry(void* argument) {
|
|
|
- [(TPPreciseTimer*)argument thread];
|
|
|
+ [(TPPreciseTimer*)CFBridgingRelease(argument) thread];
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
@@ -162,50 +162,52 @@ void thread_signal(int signal) {
|
|
|
while ( [events count] == 0 ) {
|
|
|
[condition wait];
|
|
|
}
|
|
|
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
- NSDictionary *nextEvent = [[[events objectAtIndex:0] retain] autorelease];
|
|
|
- NSTimeInterval time = [[nextEvent objectForKey:kTimeKey] unsignedLongLongValue] * timebase_ratio;
|
|
|
|
|
|
- [condition unlock];
|
|
|
-
|
|
|
- mach_wait_until((uint64_t)((time - kSpinLockTime) / timebase_ratio));
|
|
|
-
|
|
|
- if ( (double)(mach_absolute_time() * timebase_ratio) >= time-kSpinLockTime ) {
|
|
|
+ @autoreleasepool {
|
|
|
+
|
|
|
+ NSDictionary *nextEvent = [events objectAtIndex:0];
|
|
|
+ NSTimeInterval time = [[nextEvent objectForKey:kTimeKey] unsignedLongLongValue] * timebase_ratio;
|
|
|
|
|
|
- // Spin lock until it's time
|
|
|
- uint64_t end = time / timebase_ratio;
|
|
|
- while ( mach_absolute_time() < end );
|
|
|
+ [condition unlock];
|
|
|
|
|
|
+ mach_wait_until((uint64_t)((time - kSpinLockTime) / timebase_ratio));
|
|
|
+
|
|
|
+ if ( (double)(mach_absolute_time() * timebase_ratio) >= time-kSpinLockTime ) {
|
|
|
+
|
|
|
+ // Spin lock until it's time
|
|
|
+ uint64_t end = time / timebase_ratio;
|
|
|
+ while ( mach_absolute_time() < end );
|
|
|
+
|
|
|
#ifdef kAnalyzeTiming
|
|
|
- double discrepancy = (double)(mach_absolute_time()*timebase_ratio) - time;
|
|
|
- printf("TPPreciseTimer fired: %lfs time discrepancy\n", discrepancy);
|
|
|
+ double discrepancy = (double)(mach_absolute_time()*timebase_ratio) - time;
|
|
|
+ printf("TPPreciseTimer fired: %lfs time discrepancy\n", discrepancy);
|
|
|
#endif
|
|
|
-
|
|
|
- // Perform action
|
|
|
+
|
|
|
+ // Perform action
|
|
|
#if NS_BLOCKS_AVAILABLE
|
|
|
- void (^block)(void) = [nextEvent objectForKey:kBlockKey];
|
|
|
- if ( block ) {
|
|
|
- block();
|
|
|
- } else {
|
|
|
+ void (^block)(void) = [nextEvent objectForKey:kBlockKey];
|
|
|
+ if ( block ) {
|
|
|
+ block();
|
|
|
+ } else {
|
|
|
#endif
|
|
|
- id target = [nextEvent objectForKey:kTargetKey];
|
|
|
- SEL selector = NSSelectorFromString([nextEvent objectForKey:kSelectorKey]);
|
|
|
- if ( [nextEvent objectForKey:kArgumentKey] ) {
|
|
|
- [target performSelector:selector withObject:[nextEvent objectForKey:kArgumentKey]];
|
|
|
- } else {
|
|
|
- [target performSelector:selector];
|
|
|
- }
|
|
|
+ id target = [nextEvent objectForKey:kTargetKey];
|
|
|
+ SEL selector = NSSelectorFromString([nextEvent objectForKey:kSelectorKey]);
|
|
|
+ if ( [nextEvent objectForKey:kArgumentKey] ) {
|
|
|
+ [target performSelector:selector withObject:[nextEvent objectForKey:kArgumentKey]];
|
|
|
+ } else {
|
|
|
+ [target performSelector:selector];
|
|
|
+ }
|
|
|
#if NS_BLOCKS_AVAILABLE
|
|
|
- }
|
|
|
+ }
|
|
|
#endif
|
|
|
+
|
|
|
+ [condition lock];
|
|
|
+ [events removeObject:nextEvent];
|
|
|
+ } else {
|
|
|
+ [condition lock];
|
|
|
+ }
|
|
|
|
|
|
- [condition lock];
|
|
|
- [events removeObject:nextEvent];
|
|
|
- } else {
|
|
|
- [condition lock];
|
|
|
}
|
|
|
-
|
|
|
- [pool release];
|
|
|
}
|
|
|
}
|
|
|
|