@@ -39,11 +39,11 @@ #import "OFRunLoop.h" #import "OFThread.h" #import "OFList.h" #import "OFDate.h" -#import "OFSortedList.h" +#import "OFDictionary.h" #import "OFAutoreleasePool.h" #ifdef _WIN32 # include #endif @@ -93,11 +93,10 @@ [thread handleTermination]; thread->_running = OF_THREAD_WAITING_FOR_JOIN; - [OFTLSKey OF_callAllDestructors]; # 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. @@ -151,36 +150,29 @@ { return [[[self alloc] initWithThreadBlock: threadBlock] autorelease]; } # endif -+ (void)setObject: (id)object - forTLSKey: (OFTLSKey*)key -{ - id oldObject = of_tlskey_get(key->_key); - - if (!of_tlskey_set(key->_key, [object retain])) - /* FIXME: Find a better exception */ - @throw [OFInvalidArgumentException exception]; - - [oldObject release]; -} - -+ (id)objectForTLSKey: (OFTLSKey*)key -{ - return [[(id)of_tlskey_get(key->_key) retain] autorelease]; -} - + (OFThread*)currentThread { - return [[(id)of_tlskey_get(threadSelfKey) retain] autorelease]; + return of_tlskey_get(threadSelfKey); } + (OFThread*)mainThread { return mainThread; } + ++ (OFMutableDictionary*)threadDictionary +{ + OFThread *thread = of_tlskey_get(threadSelfKey); + + if (thread->_threadDictionary == nil) + thread->_threadDictionary = [[OFMutableDictionary alloc] init]; + + return thread->_threadDictionary; +} #endif + (void)sleepForTimeInterval: (double)seconds { if (seconds < 0) @@ -240,11 +232,10 @@ [thread handleTermination]; thread->_running = OF_THREAD_WAITING_FOR_JOIN; } - [OFTLSKey OF_callAllDestructors]; # 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. @@ -293,10 +284,13 @@ - (void)handleTermination { OFRunLoop *oldRunLoop = _runLoop; _runLoop = nil; [oldRunLoop release]; + + [_threadDictionary release]; + _threadDictionary = nil; } - (void)start { if (_running == OF_THREAD_RUNNING) @@ -379,11 +373,10 @@ */ if (_running == OF_THREAD_WAITING_FOR_JOIN) of_thread_detach(_thread); [_returnValue release]; - [_runLoop release]; # ifdef OF_HAVE_BLOCKS [_threadBlock release]; # endif [super dealloc];