ObjFW  Diff

Differences From Artifact [4615b52a3c]:

  • File src/OFThread.m — part of check-in [716b1fc2b3] at 2014-07-19 09:55:06 on branch trunk — Don't use C11's noreturn

    It causes just too much trouble: It breaks with some old versions of
    Clang, where noreturn does not work correctly, and OS X headers break if
    noreturn is defined, requiring an ugly and fragile workaround. It's just
    not worth the trouble it causes, as the same functionality is available
    through __attribute__((__noreturn__)). (user: js, size: 7976) [annotate] [blame] [check-ins using]

To Artifact [8e23861680]:


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# include <unistd.h>
#endif

#ifdef OF_HAVE_SCHED_YIELD
# include <sched.h>
#endif

#if defined(OF_HAVE_THREADS) && defined(__HAIKU__)
# include <kernel/OS.h>
#endif

#import "OFThread.h"
#import "OFThread+Private.h"
#import "OFRunLoop.h"
#import "OFList.h"
#import "OFDate.h"
#import "OFDictionary.h"
#import "OFAutoreleasePool.h"







<
<
<
<







32
33
34
35
36
37
38




39
40
41
42
43
44
45
# include <unistd.h>
#endif

#ifdef OF_HAVE_SCHED_YIELD
# include <sched.h>
#endif





#import "OFThread.h"
#import "OFThread+Private.h"
#import "OFRunLoop.h"
#import "OFList.h"
#import "OFDate.h"
#import "OFDictionary.h"
#import "OFAutoreleasePool.h"
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
	objc_autoreleasePoolPop(thread->_pool);
	[OFAutoreleasePool OF_handleThreadTermination];

	[thread release];

	return 0;
}

static void
setThreadName(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
}
#endif

@implementation OFThread
#ifdef OF_HAVE_THREADS
# if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
@synthesize threadBlock = _threadBlock;
# endif







<
<
<
<
<
<
<
<
<
<
<
<
<
<







109
110
111
112
113
114
115














116
117
118
119
120
121
122
	objc_autoreleasePoolPop(thread->_pool);
	[OFAutoreleasePool OF_handleThreadTermination];

	[thread release];

	return 0;
}














#endif

@implementation OFThread
#ifdef OF_HAVE_THREADS
# if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
@synthesize threadBlock = _threadBlock;
# endif
327
328
329
330
331
332
333
334



335
336
337
338
339
340
341
	_running = OF_THREAD_RUNNING;

	if (!of_thread_new(&_thread, callMain, self)) {
		[self release];
		@throw [OFThreadStartFailedException exceptionWithThread: self];
	}

	setThreadName(self);



}

- (id)join
{
	if (_running == OF_THREAD_NOT_RUNNING || !of_thread_join(_thread))
		@throw [OFThreadJoinFailedException exceptionWithThread: self];








|
>
>
>







309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
	_running = OF_THREAD_RUNNING;

	if (!of_thread_new(&_thread, callMain, self)) {
		[self release];
		@throw [OFThreadStartFailedException exceptionWithThread: self];
	}

	if (_name != nil)
		of_thread_set_name(_thread, [_name UTF8String]);
	else
		of_thread_set_name(_thread, class_getName([self class]));
}

- (id)join
{
	if (_running == OF_THREAD_NOT_RUNNING || !of_thread_join(_thread))
		@throw [OFThreadJoinFailedException exceptionWithThread: self];

373
374
375
376
377
378
379
380



381


382
383
384
385
386
387
388
	OF_GETTER(_name, true)
}

- (void)setName: (OFString*)name
{
	OF_SETTER(_name, name, true, 1)

	if (_running == OF_THREAD_RUNNING)



		setThreadName(self);


}

- (void)dealloc
{
	if (_running == OF_THREAD_RUNNING)
		@throw [OFThreadStillRunningException
		    exceptionWithThread: self];







|
>
>
>
|
>
>







358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
	OF_GETTER(_name, true)
}

- (void)setName: (OFString*)name
{
	OF_SETTER(_name, name, true, 1)

	if (_running == OF_THREAD_RUNNING) {
		if (_name != nil)
			of_thread_set_name(_thread, [_name UTF8String]);
		else
			of_thread_set_name(_thread,
			    class_getName([self class]));
	}
}

- (void)dealloc
{
	if (_running == OF_THREAD_RUNNING)
		@throw [OFThreadStillRunningException
		    exceptionWithThread: self];