@@ -52,10 +52,11 @@ #import "OFThreadJoinFailedException.h" #import "OFThreadStartFailedException.h" #import "OFThreadStillRunningException.h" #import "atomic.h" +#import "autorelease.h" #import "threading.h" static OFList *TLSKeys; static of_tlskey_t threadSelfKey; static OFThread *mainThread; @@ -62,34 +63,42 @@ static id call_main(id object) { OFThread *thread = (OFThread*)object; + void *pool; if (!of_tlskey_set(threadSelfKey, thread)) @throw [OFInitializationFailedException exceptionWithClass: [thread class]]; + + pool = objc_autoreleasePoolPush(); /* * Nasty workaround for thread implementations which can't return a * value on join. */ #ifdef OF_HAVE_BLOCKS if (thread->block != NULL) thread->returnValue = [thread->block(thread->object) retain]; else - thread->returnValue = [[thread main] retain]; -#else - thread->returnValue = [[thread main] retain]; #endif + thread->returnValue = [[thread main] retain]; [thread handleTermination]; thread->running = OF_THREAD_WAITING_FOR_JOIN; [OFTLSKey callAllDestructors]; - [OFAutoreleasePool OF_releaseAll]; +#ifdef OF_OBJFW_RUNTIME + /* + * As the values returned by objc_autoreleasePoolPush() in the ObjFW + * runtime are not actually pointers, but sequential numbers, 0 means + * we pop everything. + */ + objc_autoreleasePoolPop(0); +#endif [thread release]; return 0; } @@ -222,11 +231,18 @@ thread->running = OF_THREAD_WAITING_FOR_JOIN; } [OFTLSKey callAllDestructors]; - [OFAutoreleasePool OF_releaseAll]; +#ifdef OF_OBJFW_RUNTIME + /* + * As the values returned by objc_autoreleasePoolPush() in the ObjFW + * runtime are not actually pointers, but sequential numbers, 0 means + * we pop everything. + */ + objc_autoreleasePoolPop(0); +#endif [thread release]; of_thread_exit(); }