ObjFW  Diff

Differences From Artifact [e9c62791d8]:

To Artifact [984a3e9ddd]:


26
27
28
29
30
31
32

33
34
35
36
37
38
39
# include <unistd.h>
# include <sched.h>
#endif

#import "OFThread.h"
#import "OFList.h"
#import "OFDate.h"

#import "OFAutoreleasePool.h"

#ifdef _WIN32
# include <windows.h>
#endif

#import "OFConditionBroadcastFailedException.h"







>







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# include <unistd.h>
# include <sched.h>
#endif

#import "OFThread.h"
#import "OFList.h"
#import "OFDate.h"
#import "OFSortedList.h"
#import "OFAutoreleasePool.h"

#ifdef _WIN32
# include <windows.h>
#endif

#import "OFConditionBroadcastFailedException.h"
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
}

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


	block = [block_ copy];
	object = [object_ retain];





	return self;
}
#endif

- (id)main
{
	@throw [OFNotImplementedException exceptionWithClass: [self class]
						    selector: _cmd];

	return nil;
}

- (void)handleTermination
{







}

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







>
|
|
>
>
>
>















>
>
>
>
>
>
>







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
}

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

	@try {
		block = [block_ copy];
		object = [object_ retain];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
#endif

- (id)main
{
	@throw [OFNotImplementedException exceptionWithClass: [self class]
						    selector: _cmd];

	return nil;
}

- (void)handleTermination
{
	@synchronized (timersQueue) {
		/*
		 * Make sure we don't run old timers when the thread is
		 * restarted.
		 */
		[timersQueue removeAllObjects];
	}
}

- (void)start
{
	if (running == OF_THREAD_RUNNING)
		@throw [OFThreadStillRunningException
		    exceptionWithClass: [self class]
309
310
311
312
313
314
315












316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332

333
334
335
336
337
338
339
		    exceptionWithClass: [self class]
				thread: self];

	running = OF_THREAD_NOT_RUNNING;

	return returnValue;
}













- (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];


	[super dealloc];
}
@end

@implementation OFTLSKey
+ (void)initialize







>
>
>
>
>
>
>
>
>
>
>
>

















>







322
323
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
361
362
363
364
365
		    exceptionWithClass: [self class]
				thread: self];

	running = OF_THREAD_NOT_RUNNING;

	return returnValue;
}

- (OFSortedList*)_timersQueue
{
	if (timersQueue == nil) {
		OFSortedList *tmp = [[OFSortedList alloc] init];

		if (!of_atomic_cmpswap_ptr((void**)&timersQueue, nil, tmp))
			[tmp release];
	}

	return [[timersQueue retain] autorelease];
}

- (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];
	[timersQueue release];

	[super dealloc];
}
@end

@implementation OFTLSKey
+ (void)initialize