Browse Source

remove arc

harry 3 years ago
parent
commit
b363a2f6eb
1 changed files with 38 additions and 36 deletions
  1. 38 36
      BFCommonKit/Classes/BFUtility/TPPreciseTimer.m

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

@@ -78,7 +78,7 @@ void *thread_entry(void* argument);
     param.sched_priority = sched_get_priority_max(SCHED_FIFO);
     param.sched_priority = sched_get_priority_max(SCHED_FIFO);
     pthread_attr_setschedparam(&attr, &param);
     pthread_attr_setschedparam(&attr, &param);
     pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
     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;
     return self;
 }
 }
@@ -127,7 +127,7 @@ void *thread_entry(void* argument);
 #if NS_BLOCKS_AVAILABLE
 #if NS_BLOCKS_AVAILABLE
 - (void)scheduleBlock:(void (^)(void))block inTimeInterval:(NSTimeInterval)timeInterval {
 - (void)scheduleBlock:(void (^)(void))block inTimeInterval:(NSTimeInterval)timeInterval {
     [self addSchedule:[NSDictionary dictionaryWithObjectsAndKeys:
     [self addSchedule:[NSDictionary dictionaryWithObjectsAndKeys:
-                       [[block copy] autorelease], kBlockKey,
+                       [block copy], kBlockKey,
                        [NSNumber numberWithUnsignedLongLong:mach_absolute_time() + (timeInterval / timebase_ratio)], kTimeKey,
                        [NSNumber numberWithUnsignedLongLong:mach_absolute_time() + (timeInterval / timebase_ratio)], kTimeKey,
                        nil]];
                        nil]];
 }
 }
@@ -146,7 +146,7 @@ void *thread_entry(void* argument);
 }
 }
 
 
 void *thread_entry(void* argument) {
 void *thread_entry(void* argument) {
-    [(TPPreciseTimer*)argument thread];
+    [(TPPreciseTimer*)CFBridgingRelease(argument) thread];
     return NULL;
     return NULL;
 }
 }
 
 
@@ -162,50 +162,52 @@ void thread_signal(int signal) {
         while ( [events count] == 0 ) {
         while ( [events count] == 0 ) {
             [condition wait];
             [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
 #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
 #endif
-            
-            // Perform action
+                
+                // Perform action
 #if NS_BLOCKS_AVAILABLE
 #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
 #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
 #if NS_BLOCKS_AVAILABLE
-            }
+                }
 #endif
 #endif
+                
+                [condition lock];
+                [events removeObject:nextEvent];
+            } else {
+                [condition lock];
+            }
             
             
-            [condition lock];
-            [events removeObject:nextEvent];
-        } else {
-            [condition lock];
         }
         }
-        
-        [pool release];
     }
     }
 }
 }