@@ -18,11 +18,12 @@ #import "OFThreadPool.h" #import "OFArray.h" #import "OFList.h" #import "OFThread.h" -#import "OFAutoreleasePool.h" + +#import "autorelease.h" @interface OFThreadPoolJob: OFObject { id target; SEL selector; @@ -173,36 +174,36 @@ [super dealloc]; } - (id)main { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool; - if (terminate) { - [pool release]; + if (terminate) return nil; - } + + pool = objc_autoreleasePoolPush(); for (;;) { OFThreadPoolJob *job; [queueCondition lock]; @try { of_list_object_t *listObject; if (terminate) { - [pool release]; + objc_autoreleasePoolPop(pool); return nil; } listObject = [queue firstListObject]; while (listObject == NULL) { [queueCondition wait]; if (terminate) { - [pool release]; + objc_autoreleasePoolPop(pool); return nil; } listObject = [queue firstListObject]; } @@ -212,27 +213,28 @@ } @finally { [queueCondition unlock]; } if (terminate) { - [pool release]; + objc_autoreleasePoolPop(pool); return nil; } [job perform]; if (terminate) { - [pool release]; + objc_autoreleasePoolPop(pool); return nil; } - [pool releaseObjects]; + objc_autoreleasePoolPop(pool); + pool = objc_autoreleasePoolPush(); [countCondition lock]; @try { if (terminate) { - [pool release]; + objc_autoreleasePoolPop(pool); return nil; } (*doneCount)++; @@ -263,26 +265,27 @@ - initWithSize: (size_t)size_ { self = [super init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; size_t i; size = size_; threads = [[OFMutableArray alloc] init]; queue = [[OFList alloc] init]; queueCondition = [[OFCondition alloc] init]; countCondition = [[OFCondition alloc] init]; for (i = 0; i < size; i++) { + void *pool = objc_autoreleasePoolPush(); + OFThreadPoolThread *thread = [OFThreadPoolThread threadWithThreadPool: self]; [threads addObject: thread]; - [pool releaseObjects]; + objc_autoreleasePoolPop(pool); } /* * We need to start the threads in a separate loop to make sure * threads is not modified anymore to prevent a race condition. @@ -290,12 +293,10 @@ for (i = 0; i < size; i++) { OFThreadPoolThread *thread = [threads objectAtIndex: i]; [thread start]; } - - [pool release]; } @catch (id e) { [self release]; @throw e; } @@ -302,11 +303,11 @@ return self; } - (void)dealloc { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); [queueCondition lock]; @try { [countCondition lock]; @try { OFEnumerator *enumerator = [threads objectEnumerator]; @@ -320,11 +321,11 @@ [queueCondition broadcast]; } @finally { [queueCondition unlock]; } - [pool release]; + objc_autoreleasePoolPop(pool); [threads release]; [queue release]; [queueCondition release]; [countCondition release];