Pārlūkot izejas kodu

Revert "remove mrc"

This reverts commit 1120e09176170a340012c2adf83798e2c1af93b9.
harry 3 gadi atpakaļ
vecāks
revīzija
9c99c64d66
1 mainītis faili ar 36 papildinājumiem un 38 dzēšanām
  1. 36 38
      BFCommonKit/Classes/BFUtility/TPPreciseTimer.m

+ 36 - 38
BFCommonKit/Classes/BFUtility/TPPreciseTimer.m

@@ -78,7 +78,7 @@ void *thread_entry(void* argument);
     param.sched_priority = sched_get_priority_max(SCHED_FIFO);
     pthread_attr_setschedparam(&attr, &param);
     pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
-    pthread_create(&thread, &attr, thread_entry, (void*)CFBridgingRetain(self));
+    pthread_create(&thread, &attr, thread_entry, (void*)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], kBlockKey,
+                       [[block copy] autorelease], 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*)CFBridgingRelease(argument) thread];
+    [(TPPreciseTimer*)argument thread];
     return NULL;
 }
 
@@ -162,52 +162,50 @@ 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;
         
-        @autoreleasepool {
-            
-            NSDictionary *nextEvent = [events objectAtIndex:0];
-            NSTimeInterval time = [[nextEvent objectForKey:kTimeKey] unsignedLongLongValue] * timebase_ratio;
-            
-            [condition unlock];
+        [condition unlock];
+        
+        mach_wait_until((uint64_t)((time - kSpinLockTime) / timebase_ratio));
+        
+        if ( (double)(mach_absolute_time() * timebase_ratio) >= time-kSpinLockTime ) {
             
-            mach_wait_until((uint64_t)((time - kSpinLockTime) / timebase_ratio));
+            // Spin lock until it's time
+            uint64_t end = time / timebase_ratio;
+            while ( mach_absolute_time() < end );
             
-            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);
-#endif
-                
-                // Perform action
-#if NS_BLOCKS_AVAILABLE
-                void (^block)(void) = [nextEvent objectForKey:kBlockKey];
-                if ( block ) {
-                    block();
-                } else {
+            double discrepancy = (double)(mach_absolute_time()*timebase_ratio) - time;
+            printf("TPPreciseTimer fired: %lfs time discrepancy\n", discrepancy);
 #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];
-                    }
+            
+            // Perform action
 #if NS_BLOCKS_AVAILABLE
-                }
+            void (^block)(void) = [nextEvent objectForKey:kBlockKey];
+            if ( block ) {
+                block();
+            } else {
 #endif
-                
-                [condition lock];
-                [events removeObject:nextEvent];
+            id target = [nextEvent objectForKey:kTargetKey];
+            SEL selector = NSSelectorFromString([nextEvent objectForKey:kSelectorKey]);
+            if ( [nextEvent objectForKey:kArgumentKey] ) {
+                [target performSelector:selector withObject:[nextEvent objectForKey:kArgumentKey]];
             } else {
-                [condition lock];
+                [target performSelector:selector];
+            }
+#if NS_BLOCKS_AVAILABLE
             }
+#endif
             
+            [condition lock];
+            [events removeObject:nextEvent];
+        } else {
+            [condition lock];
         }
+        
+        [pool release];
     }
 }