@@ -101,11 +101,11 @@ callMain(id object) { OFThread *thread = (OFThread *)object; OFString *name; - if (!of_tlskey_set(threadSelfKey, thread)) + if (of_tlskey_set(threadSelfKey, thread) != 0) @throw [OFInitializationFailedException exceptionWithClass: thread.class]; #ifndef OF_OBJFW_RUNTIME thread->_pool = objc_autoreleasePoolPush(); @@ -164,11 +164,11 @@ + (void)initialize { if (self != [OFThread class]) return; - if (!of_tlskey_new(&threadSelfKey)) + if (of_tlskey_new(&threadSelfKey) != 0) @throw [OFInitializationFailedException exceptionWithClass: self]; } + (instancetype)thread @@ -348,21 +348,21 @@ { mainThread = [[OFThread alloc] init]; mainThread->_thread = of_thread_current(); mainThread->_running = OF_THREAD_RUNNING; - if (!of_tlskey_set(threadSelfKey, mainThread)) + if (of_tlskey_set(threadSelfKey, mainThread) != 0) @throw [OFInitializationFailedException exceptionWithClass: self]; } - (instancetype)init { self = [super init]; @try { - if (!of_thread_attr_init(&_attr)) + if (of_thread_attr_init(&_attr) != 0) @throw [OFInitializationFailedException exceptionWithClass: self.class]; } @catch (id e) { [self release]; @throw e; @@ -409,10 +409,12 @@ # endif } - (void)start { + int error; + if (_running == OF_THREAD_RUNNING) @throw [OFThreadStillRunningException exceptionWithThread: self]; if (_running == OF_THREAD_WAITING_FOR_JOIN) { @@ -422,30 +424,31 @@ [self retain]; _running = OF_THREAD_RUNNING; - if (!of_thread_new(&_thread, - [_name cStringWithEncoding: [OFLocale encoding]], callMain, self, - &_attr)) { + if ((error = of_thread_new(&_thread, [_name cStringWithEncoding: + [OFLocale encoding]], callMain, self, &_attr)) != 0) { [self release]; @throw [OFThreadStartFailedException exceptionWithThread: self - errNo: errno]; + errNo: error]; } } - (id)join { + int error; + if (_running == OF_THREAD_NOT_RUNNING) @throw [OFThreadJoinFailedException exceptionWithThread: self errNo: EINVAL]; - if (!of_thread_join(_thread)) + if ((error = of_thread_join(_thread)) != 0) @throw [OFThreadJoinFailedException exceptionWithThread: self - errNo: errno]; + errNo: error]; _running = OF_THREAD_NOT_RUNNING; return _returnValue; }