Index: src/OFThread.h ================================================================== --- src/OFThread.h +++ src/OFThread.h @@ -27,11 +27,11 @@ @class OFDate; @class OFSortedList; @class OFRunLoop; #ifdef OF_HAVE_BLOCKS -typedef id (^of_thread_block_t)(id object); +typedef id (^of_thread_block_t)(void); #endif /*! * @brief A class which provides portable threads. * @@ -45,13 +45,11 @@ */ @interface OFThread: OFObject { #ifdef OF_THREAD_M @public -#endif - id object; -#ifndef OF_THREAD_M +#else @private #endif of_thread_t thread; enum { OF_THREAD_NOT_RUNNING, @@ -74,18 +72,10 @@ * * @return A new, autoreleased thread */ + (instancetype)thread; -/*! - * @brief Creates a new thread with the specified object. - * - * @param object An object which is passed for use in the main method or nil - * @return A new, autoreleased thread - */ -+ (instancetype)threadWithObject: (id)object; - #ifdef OF_HAVE_BLOCKS /*! * @brief Creates a new thread with the specified block. * * @param block A block which is executed by the thread @@ -164,18 +154,10 @@ */ + (void)terminateWithObject: (id)object; + (void)OF_createMainThread; -/*! - * @brief Initializes an already allocated thread with the specified object. - * - * @param object An object which is passed for use in the main method or nil - * @return An initialized OFThread. - */ -- initWithObject: (id)object; - #ifdef OF_HAVE_BLOCKS /*! * @brief Initializes an already allocated thread with the specified block. * * @param block A block which is executed by the thread Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -68,11 +68,11 @@ * 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]; + thread->returnValue = [thread->block() retain]; else #endif thread->returnValue = [[thread main] retain]; [thread handleTermination]; @@ -112,15 +112,10 @@ + (instancetype)thread { return [[[self alloc] init] autorelease]; } -+ (instancetype)threadWithObject: (id)object -{ - return [[[self alloc] initWithObject: object] autorelease]; -} - #ifdef OF_HAVE_BLOCKS + (instancetype)threadWithBlock: (of_thread_block_t)block { return [[[self alloc] initWithBlock: block] autorelease]; } @@ -239,19 +234,10 @@ if (!of_tlskey_set(threadSelfKey, mainThread)) @throw [OFInitializationFailedException exceptionWithClass: self]; } -- initWithObject: (id)object_ -{ - self = [super init]; - - object = [object_ retain]; - - return self; -} - #ifdef OF_HAVE_BLOCKS - initWithBlock: (of_thread_block_t)block_ { self = [super init]; @@ -273,13 +259,13 @@ return nil; } - (void)handleTermination { - OFRunLoop *tmp = runLoop; + OFRunLoop *oldRunLoop = runLoop; runLoop = nil; - [tmp release]; + [oldRunLoop release]; } - (void)start { if (running == OF_THREAD_RUNNING) @@ -340,11 +326,10 @@ * the resources. */ if (running == OF_THREAD_WAITING_FOR_JOIN) of_thread_detach(thread); - [object release]; [returnValue release]; [runLoop release]; [super dealloc]; } Index: tests/OFThreadTests.m ================================================================== --- tests/OFThreadTests.m +++ tests/OFThreadTests.m @@ -28,14 +28,11 @@ @end @implementation TestThread - (id)main { - if ([object isEqual: @"foo"]) - return @"success"; - - return nil; + return @"success"; } @end @implementation TestsAppDelegate (OFThreadTests) - (void)threadTests @@ -42,12 +39,11 @@ { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; TestThread *t; OFTLSKey *key; - TEST(@"+[threadWithObject:]", - (t = [TestThread threadWithObject: @"foo"])) + TEST(@"+[thread]", (t = [TestThread thread])) TEST(@"-[start]", R([t start])) TEST(@"-[join]", [[t join] isEqual: @"success"])