@@ -95,17 +95,24 @@ static void callMain(id object) { OFThread *thread = (OFThread *)object; + OFString *name; if (!of_tlskey_set(threadSelfKey, thread)) @throw [OFInitializationFailedException exceptionWithClass: [thread class]]; thread->_pool = objc_autoreleasePoolPush(); + name = [thread name]; + if (name != nil) + of_thread_set_name([name UTF8String]); + else + of_thread_set_name(object_getClassName(thread)); + /* * Nasty workaround for thread implementations which can't return a * pointer on join. */ # ifdef OF_HAVE_BLOCKS @@ -126,10 +133,11 @@ } #endif @implementation OFThread #ifdef OF_HAVE_THREADS +@synthesize name = _name; # ifdef OF_HAVE_BLOCKS @synthesize threadBlock = _threadBlock; # endif + (void)initialize @@ -165,10 +173,13 @@ } + (OFMutableDictionary *)threadDictionary { OFThread *thread = of_tlskey_get(threadSelfKey); + + if (thread == nil) + return nil; if (thread->_threadDictionary == nil) thread->_threadDictionary = [[OFMutableDictionary alloc] init]; return thread->_threadDictionary; @@ -347,15 +358,10 @@ if (!of_thread_new(&_thread, callMain, self, &_attr)) { [self release]; @throw [OFThreadStartFailedException exceptionWithThread: self]; } - - if (_name != nil) - of_thread_set_name(_thread, [_name UTF8String]); - else - of_thread_set_name(_thread, class_getName([self class])); } - (id)join { if (_running == OF_THREAD_NOT_RUNNING || !of_thread_join(_thread)) @@ -388,26 +394,10 @@ # endif return _runLoop; } -- (OFString *)name -{ - return [[_name copy] autorelease]; -} - -- (void)setName: (OFString *)name -{ - OFString *old = name; - _name = [name copy]; - [old release]; - - if (_running == OF_THREAD_RUNNING) - of_thread_set_name(_thread, (_name != nil - ? [_name UTF8String] : class_getName([self class]))); -} - - (float)priority { return _attr.priority; }