Differences From Artifact [b48c7d5a0b]:
- File
src/OFThread.h
— part of check-in
[e8473b9db8]
at
2013-03-08 22:44:07
on branch trunk
— Document the block types.
This also removes "bool *stop" from some blocks where it does not make
sense. (user: js, size: 5380) [annotate] [blame] [check-ins using]
To Artifact [b4c8773e10]:
- File
src/OFThread.h
— part of check-in
[71d45a29d1]
at
2013-04-26 20:40:43
on branch trunk
— Make sure +[OFThread sleep*] is always available.
This means that even if --disable-threads has been specified, it is
possible to use +[OFThread sleep*] to sleep the current (and only)
thread. (user: js, size: 5523) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" | > | | > | | > > | | | | | | | | | | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #ifdef OF_HAVE_THREADS # import "OFTLSKey.h" # import "threading.h" #endif /* Haiku used to define this for some unknown reason which causes trouble */ #ifdef protected # undef protected #endif /*! @file */ @class OFDate; @class OFSortedList; @class OFRunLoop; #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 */ typedef id (^of_thread_block_t)(void); #endif /*! * @brief A class which provides portable threads. * * To use it, you should create a new class derived from it and reimplement * main. * * @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 #ifdef OF_HAVE_THREADS <OFCopying> { # ifdef OF_THREAD_M @public # else @private # endif of_thread_t _thread; enum { OF_THREAD_NOT_RUNNING, OF_THREAD_RUNNING, OF_THREAD_WAITING_FOR_JOIN } _running; # ifdef OF_HAVE_BLOCKS of_thread_block_t _block; # endif id _returnValue; OFRunLoop *_runLoop; OFString *_name; } # 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. * * @return A new, autoreleased thread */ + (instancetype)thread; # 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 /*! * @brief Sets the Thread Local Storage for the specified key. * * The specified object is first retained and then the object stored before is * released. You can specify nil as object if you want the old object to be * released and don't want any new object for the TLS key. |
︙ | ︙ | |||
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | /*! * @brief Returns the main thread. * * @return The main thread */ + (OFThread*)mainThread; /*! * @brief Suspends execution of the current thread for the specified time * interval. * * @param seconds The number of seconds to sleep */ + (void)sleepForTimeInterval: (double)seconds; /*! * @brief Suspends execution of the current thread until the specified date. * * @param date The date to wait for */ + (void)sleepUntilDate: (OFDate*)date; /*! | > | > | | | 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | /*! * @brief Returns the main thread. * * @return The main thread */ + (OFThread*)mainThread; #endif /*! * @brief Suspends execution of the current thread for the specified time * interval. * * @param seconds The number of seconds to sleep */ + (void)sleepForTimeInterval: (double)seconds; /*! * @brief Suspends execution of the current thread until the specified date. * * @param date The date to wait for */ + (void)sleepUntilDate: (OFDate*)date; /*! * @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; /*! * @brief Terminates the current thread, letting it return the specified object. * * @param object The object which the terminated thread will return */ + (void)terminateWithObject: (id)object; + (void)OF_createMainThread; # 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 /*! * @brief The main routine of the thread. You need to reimplement this! * * It can access the object passed to the threadWithObject or initWithObject * method using the instance variable named object. * |
︙ | ︙ | |||
223 224 225 226 227 228 229 230 | /*! * @brief Sets the name for the thread. * * @param name The name for the thread */ - (void)setName: (OFString*)name; @end | > | 229 230 231 232 233 234 235 236 237 | /*! * @brief Sets the name for the thread. * * @param name The name for the thread */ - (void)setName: (OFString*)name; #endif @end |