ObjFW  Diff

Differences From Artifact [378318c425]:

To Artifact [eb2ad7e37f]:


22
23
24
25
26
27
28




29
30
31
32
33
34
35

#include <math.h>

#ifndef _WIN32
# include <unistd.h>
# include <sched.h>
#endif





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







>
>
>
>







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

#include <math.h>

#ifndef _WIN32
# include <unistd.h>
# include <sched.h>
#endif

#ifdef __HAIKU__
# include <kernel/OS.h>
#endif

#import "OFThread.h"
#import "OFList.h"
#import "OFDate.h"
#import "OFSortedList.h"
#import "OFRunLoop.h"
#import "OFAutoreleasePool.h"
89
90
91
92
93
94
95













96
97
98
99
100
101
102
	objc_autoreleasePoolPop(0);
#endif

	[thread release];

	return 0;
}














@implementation OFThread
#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
@synthesize block;
#endif

+ (void)initialize







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







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
	objc_autoreleasePoolPop(0);
#endif

	[thread release];

	return 0;
}

static void
set_thread_name(OFThread *thread)
{
#ifdef __HAIKU__
	OFString *name = thread->name;

	if (name == nil)
		name = [thread className];

	rename_thread(get_pthread_thread_id(thread->thread), [name UTF8String]);
#endif
}

@implementation OFThread
#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
@synthesize block;
#endif

+ (void)initialize
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
330
331
332
333
334
335
336
337
338
339
340
341

	if (!of_thread_new(&thread, call_main, self)) {
		[self release];
		@throw [OFThreadStartFailedException
		    exceptionWithClass: [self class]
				thread: self];
	}


}

- (id)join
{
	if (running == OF_THREAD_NOT_RUNNING || !of_thread_join(thread))
		@throw [OFThreadJoinFailedException
		    exceptionWithClass: [self class]
				thread: self];

	running = OF_THREAD_NOT_RUNNING;

	return returnValue;
}






- (OFRunLoop*)runLoop
{
	if (runLoop == nil) {
		OFRunLoop *tmp = [[OFRunLoop alloc] init];

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

	return [[runLoop 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);

	[returnValue release];
	[runLoop release];

	[super dealloc];
}

- copy
{
	return [self retain];
}
@end







>
>













>
>
>
>
>












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




















<
<
<
<
<

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
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
366
367
368
369
370
371
372





373

	if (!of_thread_new(&thread, call_main, self)) {
		[self release];
		@throw [OFThreadStartFailedException
		    exceptionWithClass: [self class]
				thread: self];
	}

	set_thread_name(self);
}

- (id)join
{
	if (running == OF_THREAD_NOT_RUNNING || !of_thread_join(thread))
		@throw [OFThreadJoinFailedException
		    exceptionWithClass: [self class]
				thread: self];

	running = OF_THREAD_NOT_RUNNING;

	return returnValue;
}

- copy
{
	return [self retain];
}

- (OFRunLoop*)runLoop
{
	if (runLoop == nil) {
		OFRunLoop *tmp = [[OFRunLoop alloc] init];

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

	return [[runLoop retain] autorelease];
}

- (OFString*)name
{
	OF_GETTER(name, YES)
}

- (void)setName: (OFString*)name_
{
	OF_SETTER(name, name_, YES, YES)

	if (running == OF_THREAD_RUNNING)
		set_thread_name(self);
}

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

	[returnValue release];
	[runLoop release];

	[super dealloc];
}





@end