@@ -13,13 +13,15 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" -#import "OFTLSKey.h" +#ifdef OF_HAVE_THREADS +# import "OFTLSKey.h" -#import "threading.h" +# import "threading.h" +#endif /* Haiku used to define this for some unknown reason which causes trouble */ #ifdef protected # undef protected #endif @@ -28,11 +30,11 @@ @class OFDate; @class OFSortedList; @class OFRunLoop; -#ifdef OF_HAVE_BLOCKS +#if defined(OF_HAVE_THREADS) && defined(OF_HAVE_BLOCKS) /*! * @brief A block to be executed in a new thread. * * @return The object which should be returned when the thread is joined */ @@ -48,54 +50,56 @@ * @warning Even though the OFCopying protocol is implemented, it does *not* * return an independent copy of the thread, but instead retains it. * This is so that the thread can be used as a key for a dictionary, * so context can be associated with a thread. */ -@interface OFThread: OFObject +@interface OFThread: OFObject +#ifdef OF_HAVE_THREADS + { -#ifdef OF_THREAD_M +# ifdef OF_THREAD_M @public -#else +# else @private -#endif +# endif of_thread_t _thread; enum { OF_THREAD_NOT_RUNNING, OF_THREAD_RUNNING, OF_THREAD_WAITING_FOR_JOIN } _running; -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS of_thread_block_t _block; -#endif +# endif id _returnValue; OFRunLoop *_runLoop; OFString *_name; } -#ifdef OF_HAVE_PROPERTIES -# ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_PROPERTIES +# ifdef OF_HAVE_BLOCKS @property (copy) of_thread_block_t block; -# endif +# endif @property (copy) OFString *name; -#endif +# endif /*! * @brief Creates a new thread. * * @return A new, autoreleased thread */ + (instancetype)thread; -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS /*! * @brief Creates a new thread with the specified block. * * @param block A block which is executed by the thread * @return A new, autoreleased thread */ + (instancetype)threadWithBlock: (of_thread_block_t)block; -#endif +# endif /*! * @brief Sets the Thread Local Storage for the specified key. * * The specified object is first retained and then the object stored before is @@ -129,10 +133,11 @@ * @brief Returns the main thread. * * @return The main thread */ + (OFThread*)mainThread; +#endif /*! * @brief Suspends execution of the current thread for the specified time * interval. * @@ -146,15 +151,16 @@ * @param date The date to wait for */ + (void)sleepUntilDate: (OFDate*)date; /*! - * @brief Yields a processor voluntarily and moves the thread at the end of the + * @brief Yields a processor voluntarily and moves the thread to the end of the * queue for its priority. */ + (void)yield; +#ifdef OF_HAVE_THREADS /*! * @brief Terminates the current thread, letting it return nil. */ + (void)terminate; @@ -165,19 +171,19 @@ */ + (void)terminateWithObject: (id)object; + (void)OF_createMainThread; -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS /*! * @brief Initializes an already allocated thread with the specified block. * * @param block A block which is executed by the thread * @return An initialized OFThread. */ - initWithBlock: (of_thread_block_t)block; -#endif +# endif /*! * @brief The main routine of the thread. You need to reimplement this! * * It can access the object passed to the threadWithObject or initWithObject @@ -225,6 +231,7 @@ * @brief Sets the name for the thread. * * @param name The name for the thread */ - (void)setName: (OFString*)name; +#endif @end