ObjFW  Diff

Differences From Artifact [3ff1e2b592]:

To Artifact [a4d40e057a]:


93
94
95
96
97
98
99

100
101
102
103
104
105
106






107
108
109
110
111
112
113
static of_tlskey_t threadSelfKey;
static OFThread *mainThread;

static void
callMain(id object)
{
	OFThread *thread = (OFThread *)object;


	if (!of_tlskey_set(threadSelfKey, thread))
		@throw [OFInitializationFailedException
		    exceptionWithClass: [thread class]];

	thread->_pool = objc_autoreleasePoolPush();







	/*
	 * Nasty workaround for thread implementations which can't return a
	 * pointer on join.
	 */
# ifdef OF_HAVE_BLOCKS
	if (thread->_threadBlock != NULL)
		thread->_returnValue = [thread->_threadBlock() retain];







>







>
>
>
>
>
>







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
120
static of_tlskey_t threadSelfKey;
static OFThread *mainThread;

static void
callMain(id object)
{
	OFThread *thread = (OFThread *)object;
	OFString *name;

	if (!of_tlskey_set(threadSelfKey, thread))
		@throw [OFInitializationFailedException
		    exceptionWithClass: [thread class]];

	thread->_pool = objc_autoreleasePoolPush();

	name = [thread name];
	if (name != nil)
		of_thread_set_name([name UTF8String]);
	else
		of_thread_set_name(object_getClassName(thread));

	/*
	 * Nasty workaround for thread implementations which can't return a
	 * pointer on join.
	 */
# ifdef OF_HAVE_BLOCKS
	if (thread->_threadBlock != NULL)
		thread->_returnValue = [thread->_threadBlock() retain];
124
125
126
127
128
129
130

131
132
133
134
135
136
137

	[thread release];
}
#endif

@implementation OFThread
#ifdef OF_HAVE_THREADS

# ifdef OF_HAVE_BLOCKS
@synthesize threadBlock = _threadBlock;
# endif

+ (void)initialize
{
	if (self != [OFThread class])







>







131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

	[thread release];
}
#endif

@implementation OFThread
#ifdef OF_HAVE_THREADS
@synthesize name = _name;
# ifdef OF_HAVE_BLOCKS
@synthesize threadBlock = _threadBlock;
# endif

+ (void)initialize
{
	if (self != [OFThread class])
163
164
165
166
167
168
169



170
171
172
173
174
175
176
{
	return mainThread;
}

+ (OFMutableDictionary *)threadDictionary
{
	OFThread *thread = of_tlskey_get(threadSelfKey);




	if (thread->_threadDictionary == nil)
		thread->_threadDictionary = [[OFMutableDictionary alloc] init];

	return thread->_threadDictionary;
}
#endif







>
>
>







171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
{
	return mainThread;
}

+ (OFMutableDictionary *)threadDictionary
{
	OFThread *thread = of_tlskey_get(threadSelfKey);

	if (thread == nil)
		return nil;

	if (thread->_threadDictionary == nil)
		thread->_threadDictionary = [[OFMutableDictionary alloc] init];

	return thread->_threadDictionary;
}
#endif
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363

	_running = OF_THREAD_RUNNING;

	if (!of_thread_new(&_thread, callMain, self, &_attr)) {
		[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];








<
<
<
<
<







356
357
358
359
360
361
362





363
364
365
366
367
368
369

	_running = OF_THREAD_RUNNING;

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





}

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

386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
			_runLoop = [[OFRunLoop alloc] init];
	}
# endif

	return _runLoop;
}

- (OFString *)name
{
	return [[_name copy] autorelease];
}

- (void)setName: (OFString *)name
{
	OFString *old = name;
	_name = [name copy];
	[old release];

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

- (float)priority
{
	return _attr.priority;
}

- (void)setPriority: (float)priority
{







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







392
393
394
395
396
397
398
















399
400
401
402
403
404
405
			_runLoop = [[OFRunLoop alloc] init];
	}
# endif

	return _runLoop;
}

















- (float)priority
{
	return _attr.priority;
}

- (void)setPriority: (float)priority
{