Index: src/OFThread.h ================================================================== --- src/OFThread.h +++ src/OFThread.h @@ -59,14 +59,18 @@ #ifdef OF_HAVE_BLOCKS of_thread_block_t block; #endif id returnValue; OFRunLoop *runLoop; + OFString *name; } -#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS) +#ifdef OF_HAVE_PROPERTIES +# ifdef OF_HAVE_BLOCKS @property (copy) of_thread_block_t block; +# endif +@property (copy) OFString *name; #endif /*! * @brief Creates a new thread. * @@ -200,6 +204,20 @@ * @brief Returns the run loop for the thread. * * @return The run loop for the thread */ - (OFRunLoop*)runLoop; + +/*! + * @brief Returns the name of the thread or nil if none has been set. + * + * @return The name of the thread or nik if none has been set + */ +- (OFString*)name; + +/*! + * @brief Sets the name for the thread. + * + * @param name The name for the thread + */ +- (void)setName: (OFString*)name; @end Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -24,10 +24,14 @@ #ifndef _WIN32 # include # include #endif + +#ifdef __HAIKU__ +# include +#endif #import "OFThread.h" #import "OFList.h" #import "OFDate.h" #import "OFSortedList.h" @@ -91,10 +95,23 @@ [thread release]; return 0; } + +static void +set_thread_name(OFThread *thread) +{ +#ifdef __HAIKU__ + OFString *name = thread->name; + + if (name == nil) + name = [thread className]; + + rename_thread(get_pthread_thread_id(thread->thread), [name UTF8String]); +#endif +} @implementation OFThread #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS) @synthesize block; #endif @@ -286,10 +303,12 @@ [self release]; @throw [OFThreadStartFailedException exceptionWithClass: [self class] thread: self]; } + + set_thread_name(self); } - (id)join { if (running == OF_THREAD_NOT_RUNNING || !of_thread_join(thread)) @@ -299,10 +318,15 @@ running = OF_THREAD_NOT_RUNNING; return returnValue; } + +- copy +{ + return [self retain]; +} - (OFRunLoop*)runLoop { if (runLoop == nil) { OFRunLoop *tmp = [[OFRunLoop alloc] init]; @@ -311,10 +335,23 @@ [tmp release]; } return [[runLoop retain] autorelease]; } + +- (OFString*)name +{ + OF_GETTER(name, YES) +} + +- (void)setName: (OFString*)name_ +{ + OF_SETTER(name, name_, YES, YES) + + if (running == OF_THREAD_RUNNING) + set_thread_name(self); +} - (void)dealloc { if (running == OF_THREAD_RUNNING) @throw [OFThreadStillRunningException @@ -331,11 +368,6 @@ [returnValue release]; [runLoop release]; [super dealloc]; } - -- copy -{ - return [self retain]; -} @end