ObjFW  Check-in [c211f691e7]

Overview
Comment:OFThread: Fix setting the name on the wrong thread

This time for real.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c211f691e7e2f7a9d9e977cdf5a58419fa046abf784ebcba20e3a321cdb51a27
User & Date: js on 2017-10-07 15:12:51
Other Links: manifest | tags
Context
2017-10-07
15:19
OFHTTPClient: Fix missing exception handling check-in: e3de40a9b9 user: js tags: trunk
15:12
OFThread: Fix setting the name on the wrong thread check-in: c211f691e7 user: js tags: trunk
14:57
OFThread: Support setting the name while running check-in: 76ee8ab481 user: js tags: trunk
Changes

Modified src/OFThread.m from [2f9aa72b9d] to [41a9132f9a].

94
95
96
97
98
99
100

101
102
103
104
105
106
107







108
109
110
111
112
113
114
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];







>







>
>
>
>
>
>
>







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
121
122
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 cStringWithEncoding: [OFLocalization encoding]]);
	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];
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382

	_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(
		    [_name cStringWithEncoding: [OFLocalization encoding]]);
	else
		of_thread_set_name(class_getName([self class]));
}

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








<
<
<
<
<
<







371
372
373
374
375
376
377






378
379
380
381
382
383
384

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