ObjFW  Diff

Differences From Artifact [965a5e323a]:

To Artifact [94d47672c0]:


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
#endif
	void (*destructor)(id);
	of_list_object_t *listObject;
	BOOL initialized;
}

/**


 * \return A new autoreleased Thread Local Storage key
 */
+ TLSKey;

/**


 * \param destructor A destructor that is called when the thread is terminated
 * \return A new autoreleased Thread Local Storage key
 */
+ TLSKeyWithDestructor: (void(*)(id))destructor;

+ (void)callAllDestructors;

/**
 * \return An initialized Thread Local Storage key
 */
- init;

/**
 * \param destructor A destructor that is called when the thread is terminated
 * \return An initialized Thread Local Storage key
 */
- initWithDestructor: (void(*)(id))destructor;
@end

/**







>
>
|




>
>








|
|
<
|
<







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
#endif
	void (*destructor)(id);
	of_list_object_t *listObject;
	BOOL initialized;
}

/**
 * \brief Creates a new Thread Local Storage key
 *
 * \return A new, autoreleased Thread Local Storage key
 */
+ TLSKey;

/**
 * \brief Creates a new Thread Local Storage key with the specified destructor.
 *
 * \param destructor A destructor that is called when the thread is terminated
 * \return A new autoreleased Thread Local Storage key
 */
+ TLSKeyWithDestructor: (void(*)(id))destructor;

+ (void)callAllDestructors;

/**
 * \brief Initializes an already allocated Thread Local Storage Key with the
 *	  specified destructor.

 *

 * \param destructor A destructor that is called when the thread is terminated
 * \return An initialized Thread Local Storage key
 */
- initWithDestructor: (void(*)(id))destructor;
@end

/**
90
91
92
93
94
95
96


97
98
99
100
101


102
103
104
105
106
107
108


109
110
111
112
113
114


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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
192
193
194
195
196
197


198
199
200
201
202
203



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250


251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283


284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
}

#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
@property (retain) of_thread_block_t block;
#endif

/**


 * \return A new, autoreleased thread
 */
+ thread;

/**


 * \param object An object which is passed for use in the main method or nil
 * \return A new, autoreleased thread
 */
+ threadWithObject: (id)object;

#ifdef OF_HAVE_BLOCKS
/**


 * \param block A block which is executed by the thread
 * \return A new, autoreleased thread
 */
+ threadWithBlock: (of_thread_block_t)block;

/**


 * \param block A block which is executed by the thread
 * \param object An object which is passed for use in the main method or nil
 * \return A new, autoreleased thread
 */
+ threadWithBlock: (of_thread_block_t)block
	   object: (id)object;
#endif

/**
 * 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.
 *
 * \param key The Thread Local Storage key
 * \param object The object the Thread Local Storage key will be set to
 */
+ (void)setObject: (id)object
	forTLSKey: (OFTLSKey*)key;

/**
 * Returns the object for the specified Thread Local Storage key.
 *
 * The returned object is <i>not</i> retained and autoreleased for performance
 * reasons!
 *
 * \param key The Thread Local Storage key
 */
+ (id)objectForTLSKey: (OFTLSKey*)key;

/**


 * \return The current thread or nil if we are in the main thread
 */
+ (OFThread*)currentThread;

/**
 * Suspends execution of the current thread for the specified time interval.

 *
 * \param seconds The number of seconds to sleep
 */
+ (void)sleepForTimeInterval: (int64_t)seconds;

/**
 * Suspends execution of the current thread for the specified time interval.

 *
 * \param seconds The number of seconds to sleep
 * \param microseconds The number of microseconds to sleep
 */
+ (void)sleepForTimeInterval: (int64_t)seconds
		microseconds: (uint32_t)microseconds;

/**
 * Suspends execution of the current thread until the specified date.


 */
+ (void)sleepUntilDate: (OFDate*)date;

/**
 * Yields a processor voluntarily and moves the thread at the end of the queue
 * for its priority.
 */
+ (void)yield;

/**
 * Terminates the current thread, letting it return nil.
 */
+ (void)terminate;

/**
 * Terminates the current thread, letting it return the specified object.
 *
 * \param object The object which the terminated thread will return
 */
+ (void)terminateWithObject: (id)object;

/**


 * \param object An object which is passed for use in the main method or nil
 * \return An initialized OFThread.
 */
- initWithObject: (id)object;

#ifdef OF_HAVE_BLOCKS
/**


 * \param block A block which is executed by the thread
 * \return An initialized OFThread.
 */
- initWithBlock: (of_thread_block_t)block;

/**



 * \param block A block which is executed by the thread
 * \param object An object which is passed for use in the main method or nil
 * \return An initialized OFThread.
 */
- initWithBlock: (of_thread_block_t)block
	 object: (id)object;
#endif

/**
 * 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.
 *
 * \return The object the join method should return when called for this thread
 */
- (id)main;

/**
 * This routine is exectued when the thread's main method has finished executing
 * or terminate has been called.
 */
- (void)handleTermination;

/**
 * Starts the thread.
 */
- (void)start;

/**
 * Joins a thread.
 *
 * \return The object returned by the main method of the thread.
 */
- (id)join;
@end

/**
 * \brief A class for creating mutual exclusions.
 */
@interface OFMutex: OFObject
{
	of_mutex_t mutex;
	BOOL initialized;
}

/**


 * \return A new autoreleased mutex.
 */
+ mutex;

/**
 * Locks the mutex.
 */
- (void)lock;

/**
 * Tries to lock the mutex and returns a boolean whether the mutex could be
 * acquired.
 *
 * \return A boolean whether the mutex could be acquired
 */
- (BOOL)tryLock;

/**
 * Unlocks the mutex.
 */
- (void)unlock;
@end

/**
 * \brief A class implementing a condition variable for thread synchronization.
 */
@interface OFCondition: OFMutex
{
	of_condition_t condition;
	BOOL conditionInitialized;
}

/**


 * \return A new, autoreleased OFCondition
 */
+ condition;

/**
 * Blocks the current thread until another thread calls -[signal] or
 * -[broadcast].
 */
- (void)wait;

/**
 * Signals the next waiting thread to continue.
 */
- (void)signal;

/**
 * Signals all threads to continue.
 */
- (void)broadcast;
@end







>
>





>
>







>
>






>
>









|












|









>
>





|
>






|
>








|
>
>




|
|




|




|






>
>







>
>






>
>
>









|









|
|




|




|
















>
>





|




|
<






|














>
>





|
|




|




|



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286

287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
}

#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
@property (retain) of_thread_block_t block;
#endif

/**
 * \brief Creates a new thread.
 *
 * \return A new, autoreleased thread
 */
+ thread;

/**
 * \brief Creates a new thread with the specified object.
 *
 * \param object An object which is passed for use in the main method or nil
 * \return A new, autoreleased thread
 */
+ threadWithObject: (id)object;

#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
 */
+ threadWithBlock: (of_thread_block_t)block;

/**
 * \brief Creates a new thread with the specified block and object.
 *
 * \param block A block which is executed by the thread
 * \param object An object which is passed for use in the main method or nil
 * \return A new, autoreleased thread
 */
+ threadWithBlock: (of_thread_block_t)block
	   object: (id)object;
#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.
 *
 * \param key The Thread Local Storage key
 * \param object The object the Thread Local Storage key will be set to
 */
+ (void)setObject: (id)object
	forTLSKey: (OFTLSKey*)key;

/**
 * \brief Returns the object for the specified Thread Local Storage key.
 *
 * The returned object is <i>not</i> retained and autoreleased for performance
 * reasons!
 *
 * \param key The Thread Local Storage key
 */
+ (id)objectForTLSKey: (OFTLSKey*)key;

/**
 * \brief Returns the current thread.
 *
 * \return The current thread or nil if we are in the main thread
 */
+ (OFThread*)currentThread;

/**
 * \brief Suspends execution of the current thread for the specified time
 *	  interval.
 *
 * \param seconds The number of seconds to sleep
 */
+ (void)sleepForTimeInterval: (int64_t)seconds;

/**
 * \brief Suspends execution of the current thread for the specified time
 *	  interval.
 *
 * \param seconds The number of seconds to sleep
 * \param microseconds The number of microseconds to sleep
 */
+ (void)sleepForTimeInterval: (int64_t)seconds
		microseconds: (uint32_t)microseconds;

/**
 * \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 at the end of the
 *	  queue for its priority.
 */
+ (void)yield;

/**
 * \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;

/**
 * \brief Initializes an already allocated thread with the specified object.
 *
 * \param object An object which is passed for use in the main method or nil
 * \return An initialized OFThread.
 */
- initWithObject: (id)object;

#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;

/**
 * \brief Initializes an already allocated thread with the specified block and
 *	  object.
 *
 * \param block A block which is executed by the thread
 * \param object An object which is passed for use in the main method or nil
 * \return An initialized OFThread.
 */
- initWithBlock: (of_thread_block_t)block
	 object: (id)object;
#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.
 *
 * \return The object the join method should return when called for this thread
 */
- (id)main;

/**
 * \brief This routine is exectued when the thread's main method has finished
 *	  executing or terminate has been called.
 */
- (void)handleTermination;

/**
 * \brief Starts the thread.
 */
- (void)start;

/**
 * \brief Joins a thread.
 *
 * \return The object returned by the main method of the thread.
 */
- (id)join;
@end

/**
 * \brief A class for creating mutual exclusions.
 */
@interface OFMutex: OFObject
{
	of_mutex_t mutex;
	BOOL initialized;
}

/**
 * \brief Creates a new mutex.
 *
 * \return A new autoreleased mutex.
 */
+ mutex;

/**
 * \brief Locks the mutex.
 */
- (void)lock;

/**
 * \brief Tries to lock the mutex.

 *
 * \return A boolean whether the mutex could be acquired
 */
- (BOOL)tryLock;

/**
 * \brief Unlocks the mutex.
 */
- (void)unlock;
@end

/**
 * \brief A class implementing a condition variable for thread synchronization.
 */
@interface OFCondition: OFMutex
{
	of_condition_t condition;
	BOOL conditionInitialized;
}

/**
 * \brief Creates a new condition.
 *
 * \return A new, autoreleased OFCondition
 */
+ condition;

/**
 * \brief Blocks the current thread until another thread calls -[signal] or
 *	  -[broadcast].
 */
- (void)wait;

/**
 * \brief Signals the next waiting thread to continue.
 */
- (void)signal;

/**
 * \brief Signals all threads to continue.
 */
- (void)broadcast;
@end