ObjFW  Diff

Differences From Artifact [94dbbf6fa0]:

To Artifact [378318c425]:


66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
66
67
68
69
70
71
72

73
74
75
76
77
78
79
80







-
+








	/*
	 * Nasty workaround for thread implementations which can't return a
	 * value on join.
	 */
#ifdef OF_HAVE_BLOCKS
	if (thread->block != NULL)
		thread->returnValue = [thread->block(thread->object) retain];
		thread->returnValue = [thread->block() retain];
	else
#endif
		thread->returnValue = [[thread main] retain];

	[thread handleTermination];

	thread->running = OF_THREAD_WAITING_FOR_JOIN;
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
110
111
112
113
114
115
116





117
118
119
120
121
122
123







-
-
-
-
-







}

+ (instancetype)thread
{
	return [[[self alloc] init] autorelease];
}

+ (instancetype)threadWithObject: (id)object
{
	return [[[self alloc] initWithObject: object] autorelease];
}

#ifdef OF_HAVE_BLOCKS
+ (instancetype)threadWithBlock: (of_thread_block_t)block
{
	return [[[self alloc] initWithBlock: block] autorelease];
}
#endif

237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
232
233
234
235
236
237
238









239
240
241
242
243
244
245







-
-
-
-
-
-
-
-
-







	mainThread->thread = of_thread_current();

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

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

	object = [object_ retain];

	return self;
}

#ifdef OF_HAVE_BLOCKS
- initWithBlock: (of_thread_block_t)block_
{
	self = [super init];

	@try {
		block = [block_ copy];
271
272
273
274
275
276
277
278

279
280

281
282
283
284
285
286
287
257
258
259
260
261
262
263

264
265

266
267
268
269
270
271
272
273







-
+

-
+







	[[OFRunLoop currentRunLoop] run];

	return nil;
}

- (void)handleTermination
{
	OFRunLoop *tmp = runLoop;
	OFRunLoop *oldRunLoop = runLoop;
	runLoop = nil;
	[tmp release];
	[oldRunLoop release];
}

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

331
332
333
334
335
336
337
338
339
340
341







-











	/*
	 * 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];
}
@end