︙ | | | ︙ | |
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
|
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include <setjmp.h>
#import "OFObject.h"
#ifdef OF_HAVE_THREADS
# import "thread.h"
#endif
OF_ASSUME_NONNULL_BEGIN
/** @file */
@class OFDate;
#ifdef OF_HAVE_SOCKETS
@class OFDNSResolver;
#endif
@class OFRunLoop;
@class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
#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 _Nullable (^of_thread_block_t)(void);
#endif
/**
* @class OFThread OFThread.h ObjFW/OFThread.h
*
* @brief A class which provides portable threads.
*
|
<
|
|
|
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
|
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include <setjmp.h>
#import "OFObject.h"
#ifdef OF_HAVE_THREADS
# import "OFPlainThread.h"
#endif
OF_ASSUME_NONNULL_BEGIN
/** @file */
@class OFDate;
#ifdef OF_HAVE_SOCKETS
@class OFDNSResolver;
#endif
@class OFRunLoop;
@class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
#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 _Nullable (^OFThreadBlock)(void);
#endif
/**
* @class OFThread OFThread.h ObjFW/OFThread.h
*
* @brief A class which provides portable threads.
*
|
︙ | | | ︙ | |
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
|
* so context can be associated with a thread.
*/
@interface OFThread: OFObject
#ifdef OF_HAVE_THREADS
<OFCopying>
{
@private
of_thread_t _thread;
of_thread_attr_t _attr;
enum of_thread_running {
OF_THREAD_NOT_RUNNING,
OF_THREAD_RUNNING,
OF_THREAD_WAITING_FOR_JOIN
} _running;
# ifndef OF_OBJFW_RUNTIME
void *_pool;
# endif
# ifdef OF_HAVE_BLOCKS
of_thread_block_t _Nullable _threadBlock;
# endif
jmp_buf _exitEnv;
id _returnValue;
bool _supportsSockets;
OFRunLoop *_Nullable _runLoop;
OFMutableDictionary *_threadDictionary;
OFString *_Nullable _name;
|
|
|
|
|
|
|
|
|
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
|
* so context can be associated with a thread.
*/
@interface OFThread: OFObject
#ifdef OF_HAVE_THREADS
<OFCopying>
{
@private
OFPlainThread _thread;
OFPlainThreadAttributes _attr;
enum OFThreadState {
OFThreadStateNotRunning,
OFThreadStateRunning,
OFThreadStateWaitingForJoin
} _running;
# ifndef OF_OBJFW_RUNTIME
void *_pool;
# endif
# ifdef OF_HAVE_BLOCKS
OFThreadBlock _Nullable _threadBlock;
# endif
jmp_buf _exitEnv;
id _returnValue;
bool _supportsSockets;
OFRunLoop *_Nullable _runLoop;
OFMutableDictionary *_threadDictionary;
OFString *_Nullable _name;
|
︙ | | | ︙ | |
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
*/
@property OF_NULLABLE_PROPERTY (copy) OFString *name;
# ifdef OF_HAVE_BLOCKS
/**
* @brief The block to execute in the thread.
*/
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
of_thread_block_t threadBlock;
# endif
/**
* @brief The run loop for the thread.
*/
@property (readonly, nonatomic) OFRunLoop *runLoop;
|
|
<
|
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
*/
@property OF_NULLABLE_PROPERTY (copy) OFString *name;
# ifdef OF_HAVE_BLOCKS
/**
* @brief The block to execute in the thread.
*/
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFThreadBlock threadBlock;
# endif
/**
* @brief The run loop for the thread.
*/
@property (readonly, nonatomic) OFRunLoop *runLoop;
|
︙ | | | ︙ | |
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
# ifdef OF_HAVE_BLOCKS
/**
* @brief Creates a new thread with the specified block.
*
* @param threadBlock A block which is executed by the thread
* @return A new, autoreleased thread
*/
+ (instancetype)threadWithThreadBlock: (of_thread_block_t)threadBlock;
# endif
/**
* @brief Returns the current thread.
*
* @return The current thread
*/
|
|
|
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
# ifdef OF_HAVE_BLOCKS
/**
* @brief Creates a new thread with the specified block.
*
* @param threadBlock A block which is executed by the thread
* @return A new, autoreleased thread
*/
+ (instancetype)threadWithThreadBlock: (OFThreadBlock)threadBlock;
# endif
/**
* @brief Returns the current thread.
*
* @return The current thread
*/
|
︙ | | | ︙ | |
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
/**
* @brief Suspends execution of the current thread for the specified time
* interval.
*
* @param timeInterval The number of seconds to sleep
*/
+ (void)sleepForTimeInterval: (of_time_interval_t)timeInterval;
/**
* @brief Suspends execution of the current thread until the specified date.
*
* @param date The date to wait for
*/
+ (void)sleepUntilDate: (OFDate *)date;
|
|
|
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
/**
* @brief Suspends execution of the current thread for the specified time
* interval.
*
* @param timeInterval The number of seconds to sleep
*/
+ (void)sleepForTimeInterval: (OFTimeInterval)timeInterval;
/**
* @brief Suspends execution of the current thread until the specified date.
*
* @param date The date to wait for
*/
+ (void)sleepUntilDate: (OFDate *)date;
|
︙ | | | ︙ | |
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
# ifdef OF_HAVE_BLOCKS
/**
* @brief Initializes an already allocated thread with the specified block.
*
* @param threadBlock A block which is executed by the thread
* @return An initialized OFThread.
*/
- (instancetype)initWithThreadBlock: (of_thread_block_t)threadBlock;
# endif
/**
* @brief The main routine of the thread. You need to reimplement this!
*
* @return The object the join method should return when called for this thread
*/
|
|
|
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
# ifdef OF_HAVE_BLOCKS
/**
* @brief Initializes an already allocated thread with the specified block.
*
* @param threadBlock A block which is executed by the thread
* @return An initialized OFThread.
*/
- (instancetype)initWithThreadBlock: (OFThreadBlock)threadBlock;
# endif
/**
* @brief The main routine of the thread. You need to reimplement this!
*
* @return The object the join method should return when called for this thread
*/
|
︙ | | | ︙ | |