Index: src/OFRunLoop.m ================================================================== --- src/OFRunLoop.m +++ src/OFRunLoop.m @@ -101,26 +101,17 @@ return [[mainRunLoop retain] autorelease]; } + (OFRunLoop*)currentRunLoop { - OFThread *currentThread = [OFThread currentThread]; - OFRunLoop *runLoop = [currentThread runLoop]; - - if (runLoop != nil) - return runLoop; - - runLoop = [[[OFRunLoop alloc] init] autorelease]; - [currentThread OF_setRunLoop: runLoop]; - - return runLoop; + return [[OFThread currentThread] runLoop]; } + (void)OF_setMainRunLoop { void *pool = objc_autoreleasePoolPush(); - mainRunLoop = [[[OFThread currentThread] runLoop] retain]; + mainRunLoop = [[self currentRunLoop] retain]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS + (void)OF_addAsyncReadForStream: (OFStream*)stream Index: src/OFThread.h ================================================================== --- src/OFThread.h +++ src/OFThread.h @@ -273,17 +273,15 @@ * \return The object returned by the main method of the thread. */ - (id)join; /** - * \brief Returns the run loop for the thread or nil if it has no run loop. + * \brief Returns the run loop for the thread. * - * \return The run loop for the thread or nil if it has no run loop + * \return The run loop for the thread */ - (OFRunLoop*)runLoop; - -- (void)OF_setRunLoop: (OFRunLoop*)runLoop; @end /** * \brief A class for creating mutual exclusions. */ Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -238,14 +238,28 @@ if (!of_tlskey_set(threadSelfKey, mainThread)) @throw [OFInitializationFailedException exceptionWithClass: self]; } -- initWithObject: (id)object_ +- init { self = [super init]; + @try { + runLoop = [[OFRunLoop alloc] init]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- initWithObject: (id)object_ +{ + self = [self init]; + object = [object_ retain]; return self; } @@ -257,11 +271,11 @@ } - initWithObject: (id)object_ block: (of_thread_block_t)block_ { - self = [super init]; + self = [self init]; @try { object = [object_ retain]; block = [block_ copy]; } @catch (id e) { @@ -281,12 +295,13 @@ return nil; } - (void)handleTermination { - [runLoop release]; - runLoop = nil; + OFRunLoop *old = runLoop; + runLoop = [[OFRunLoop alloc] init]; + [old release]; } - (void)start { if (running == OF_THREAD_RUNNING) @@ -326,17 +341,10 @@ - (OFRunLoop*)runLoop { return [[runLoop retain] autorelease]; } -- (void)OF_setRunLoop: (OFRunLoop*)runLoop_ -{ - OFRunLoop *old = runLoop; - runLoop = [runLoop_ retain]; - [old release]; -} - - (void)dealloc { if (running == OF_THREAD_RUNNING) @throw [OFThreadStillRunningException exceptionWithClass: [self class] @@ -349,10 +357,11 @@ if (running == OF_THREAD_WAITING_FOR_JOIN) of_thread_detach(thread); [object release]; [returnValue release]; + [runLoop release]; [super dealloc]; } - copy