Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -183,14 +183,10 @@ [OBJCFLAGS="$OBJCFLAGS -Wundeclared-selector"]) AX_CHECK_COMPILER_FLAGS([-Wsemicolon-before-method-body -Werror], [OBJCFLAGS="$OBJCFLAGS -Wsemicolon-before-method-body"]) AX_CHECK_COMPILER_FLAGS([-Wobjc-missing-property-synthesis -Werror], [OBJCFLAGS="$OBJCFLAGS -Wobjc-missing-property-synthesis"]) -AX_CHECK_COMPILER_FLAGS([-Watomic-properties -Werror], [ - OBJCFLAGS="$OBJCFLAGS -Watomic-properties" - TESTS_OBJCFLAGS="$TESTS_OBJCFLAGS -Wno-atomic-properties" -]) AC_MSG_CHECKING(whether Objective C compiler supports properties) AC_TRY_COMPILE([ #ifdef __has_attribute # if __has_attribute(objc_root_class) Index: src/OFThread.h ================================================================== --- src/OFThread.h +++ src/OFThread.h @@ -77,12 +77,17 @@ OFString *_Nullable _name; } /*! * The name for the thread to use when starting it. + * + * @note While this can be changed after the thread has been started, it will + * have no effect once the thread started. If you want to change the name + * of the current thread after it has been started, look at the class + * method @ref setName:. */ -@property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *name; +@property OF_NULLABLE_PROPERTY (copy) OFString *name; # ifdef OF_HAVE_BLOCKS /*! * The block to execute in the thread. */ @@ -162,10 +167,27 @@ * * @param object The object which the terminated thread will return */ + (void)terminateWithObject: (nullable id)object OF_NO_RETURN; +/*! + * @brief Sets the name of the current thread. + * + * Unlike the instance method, this can be used after the thread has been + * started. + * + * @param name The new name for the current thread. + */ ++ (void)setName: (nullable OFString *)name; + +/*! + * @brief Returns the name of the current thread. + * + * @return The name of the current thread. + */ ++ (nullable OFString *)name; + # ifdef OF_HAVE_BLOCKS /*! * @brief Initializes an already allocated thread with the specified block. * * @param threadBlock A block which is executed by the thread Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -49,17 +49,18 @@ # include <3ds/svc.h> #endif #import "OFThread.h" #import "OFThread+Private.h" -#import "OFRunLoop.h" -#import "OFString.h" -#import "OFList.h" +#import "OFAutoreleasePool+Private.h" +#import "OFAutoreleasePool.h" #import "OFDate.h" #import "OFDictionary.h" -#import "OFAutoreleasePool.h" -#import "OFAutoreleasePool+Private.h" +#import "OFList.h" +#import "OFLocalization.h" +#import "OFRunLoop.h" +#import "OFString.h" #ifdef OF_WINDOWS # include #endif @@ -269,10 +270,26 @@ [thread release]; of_thread_exit(); } + ++ (void)setName: (OFString *)name +{ + [[OFThread currentThread] setName: name]; + + if (name != nil) + of_thread_set_name( + [name cStringWithEncoding: [OFLocalization encoding]]); + else + of_thread_set_name(class_getName([self class])); +} + ++ (OFString *)name +{ + return [[OFThread currentThread] name]; +} + (void)of_createMainThread { mainThread = [[OFThread alloc] init]; mainThread->_thread = of_thread_current(); @@ -350,11 +367,12 @@ [self release]; @throw [OFThreadStartFailedException exceptionWithThread: self]; } if (_name != nil) - of_thread_set_name([_name UTF8String]); + of_thread_set_name( + [_name cStringWithEncoding: [OFLocalization encoding]]); else of_thread_set_name(class_getName([self class])); } - (id)join