ObjFW  Check-in [4c8f9edda8]

Overview
Comment:Every OFThread now always has a run loop.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4c8f9edda86682c869678c3cb8c70dc7ba186fb8a56af1de157a32dbb52104f1
User & Date: js on 2012-09-16 22:26:51
Other Links: manifest | tags
Context
2012-09-16
22:29
Add -[OFTimer waitUntilDone]. check-in: c96dbe88c6 user: js tags: trunk
22:26
Every OFThread now always has a run loop. check-in: 4c8f9edda8 user: js tags: trunk
22:16
Make sure an autorelease pool is always in place. check-in: cc9601c228 user: js tags: trunk
Changes

Modified src/OFRunLoop.m from [cf11bcd288] to [4507c3903b].

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
99
100
101
102
103
104
105

106









107
108
109
110
111

112
113
114
115
116
117
118
119







-
+
-
-
-
-
-
-
-
-
-





-
+







+ (OFRunLoop*)mainRunLoop
{
	return [[mainRunLoop retain] autorelease];
}

+ (OFRunLoop*)currentRunLoop
{
	OFThread *currentThread = [OFThread currentThread];
	return [[OFThread currentThread] runLoop];
	OFRunLoop *runLoop = [currentThread runLoop];

	if (runLoop != nil)
		return runLoop;

	runLoop = [[[OFRunLoop alloc] init] autorelease];
	[currentThread OF_setRunLoop: runLoop];

	return runLoop;
}

+ (void)OF_setMainRunLoop
{
	void *pool = objc_autoreleasePoolPush();
	mainRunLoop = [[[OFThread currentThread] runLoop] retain];
	mainRunLoop = [[self currentRunLoop] retain];
	objc_autoreleasePoolPop(pool);
}

#ifdef OF_HAVE_BLOCKS
+ (void)OF_addAsyncReadForStream: (OFStream*)stream
			buffer: (void*)buffer
			length: (size_t)length

Modified src/OFThread.h from [ea0984f710] to [fd48a1729f].

271
272
273
274
275
276
277
278

279
280

281
282
283
284
285
286
287
288
289
290
291
271
272
273
274
275
276
277

278
279

280
281
282


283
284
285
286
287
288
289







-
+

-
+


-
-







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

/**
 * \brief Returns the run loop for the thread or nil if it has no run loop.
 * \brief Returns the run loop for the thread.
 *
 * \return The run loop for the thread or nil if it has no run loop
 * \return The run loop for the thread
 */
- (OFRunLoop*)runLoop;

- (void)OF_setRunLoop: (OFRunLoop*)runLoop;
@end

/**
 * \brief A class for creating mutual exclusions.
 */
@interface OFMutex: OFObject
{

Modified src/OFThread.m from [bf828006aa] to [80338cd99b].

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







-
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+















-
+







	mainThread->thread = of_thread_current();

	if (!of_tlskey_set(threadSelfKey, mainThread))
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
}

- initWithObject: (id)object_
- init
{
	self = [super init];

	@try {
		runLoop = [[OFRunLoop alloc] init];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- initWithObject: (id)object_
{
	self = [self init];

	object = [object_ retain];

	return self;
}

#ifdef OF_HAVE_BLOCKS
- initWithBlock: (of_thread_block_t)block_
{
	return [self initWithObject: nil
			      block: block_];
}

- initWithObject: (id)object_
	   block: (of_thread_block_t)block_
{
	self = [super init];
	self = [self init];

	@try {
		object = [object_ retain];
		block = [block_ copy];
	} @catch (id e) {
		[self release];
		@throw e;
279
280
281
282
283
284
285
286
287



288
289
290
291
292
293
294
293
294
295
296
297
298
299


300
301
302
303
304
305
306
307
308
309







-
-
+
+
+







						    selector: _cmd];

	return nil;
}

- (void)handleTermination
{
	[runLoop release];
	runLoop = nil;
	OFRunLoop *old = runLoop;
	runLoop = [[OFRunLoop alloc] init];
	[old release];
}

- (void)start
{
	if (running == OF_THREAD_RUNNING)
		@throw [OFThreadStillRunningException
		    exceptionWithClass: [self class]
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353

354
355
356
357
358
359
360
339
340
341
342
343
344
345







346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369







-
-
-
-
-
-
-
















+







}

- (OFRunLoop*)runLoop
{
	return [[runLoop retain] autorelease];
}

- (void)OF_setRunLoop: (OFRunLoop*)runLoop_
{
	OFRunLoop *old = runLoop;
	runLoop = [runLoop_ retain];
	[old release];
}

- (void)dealloc
{
	if (running == OF_THREAD_RUNNING)
		@throw [OFThreadStillRunningException
		    exceptionWithClass: [self class]
				thread: self];

	/*
	 * We should not be running anymore, but call detach in order to free
	 * the resources.
	 */
	if (running == OF_THREAD_WAITING_FOR_JOIN)
		of_thread_detach(thread);

	[object release];
	[returnValue release];
	[runLoop release];

	[super dealloc];
}

- copy
{
	return [self retain];