Index: src/OFThread.h ================================================================== --- src/OFThread.h +++ src/OFThread.h @@ -20,16 +20,26 @@ { @public of_tlskey_t key; } +/** + * \return A new autoreleased Thread Local Storage key + */ ++ tlsKey; + /** * \param destructor A destructor that is called when the thread is terminated * \return A new autoreleased Thread Local Storage key */ + tlsKeyWithDestructor: (void(*)(id))destructor; +/** + * \return An initialized Thread Local Storage key + */ +- init; + /** * \param destructor A destructor that is called when the thread is terminated * \return An initialized Thread Local Storage key */ - initWithDestructor: (void(*)(id))destructor; Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -99,14 +99,32 @@ [super dealloc]; } @end @implementation OFTLSKey ++ tlsKey +{ + return [[[self alloc] init] autorelease]; +} + + tlsKeyWithDestructor: (void(*)(id))destructor { return [[[self alloc] initWithDestructor: destructor] autorelease]; } + +- init +{ + self = [super init]; + + if (!of_tlskey_new(&key, NULL)) { + Class c = isa; + [super dealloc]; + @throw [OFInitializationFailedException newWithClass: c]; + } + + return self; +} - initWithDestructor: (void(*)(id))destructor { self = [super init];