ObjFW  Check-in [bc76c7f2b0]

Overview
Comment:Call objc_thread_{add,remove} when using the GNU runtime.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: bc76c7f2b03756723fc475af44008990bd1334dd310cc7224fd7a99301b95b69
User & Date: js on 2011-04-12 15:26:54
Other Links: manifest | tags
Context
2011-04-12
15:26
Call objc_thread_{add,remove} when using the GNU runtime. check-in: bc76c7f2b0 user: js tags: trunk
14:51
Use void in declarations when we take no parameters. check-in: c02e48e140 user: js tags: trunk
13:21
Release the old return value when restarting a thread. check-in: b3fa788a4e user: js tags: trunk
Changes

Modified src/OFThread.m from [593c914f01] to [56ad3d2bba].

18
19
20
21
22
23
24




25
26
27
28
29
30
31

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





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

#import "OFConditionBroadcastFailedException.h"







>
>
>
>







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

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

#if defined(OF_GNU_RUNTIME) || defined(OF_OLD_GNU_RUNTIME)
# import <objc/thr.h>
#endif

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

#import "OFConditionBroadcastFailedException.h"
47
48
49
50
51
52
53




54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71




72
73
74
75
76
77
78

static OFList *tlskeys;
static of_tlskey_t thread_self;

static id
call_main(id obj)
{




	if (!of_tlskey_set(thread_self, obj))
		@throw [OFInitializationFailedException
		    newWithClass: [obj class]];

	/*
	 * Nasty workaround for thread implementations which can't return a
	 * value on join.
	 */
	((OFThread*)obj)->retval = [[obj main] retain];

	[obj handleTermination];

	((OFThread*)obj)->running = OF_THREAD_WAITING_FOR_JOIN;

	[OFTLSKey callAllDestructors];
	[OFAutoreleasePool releaseAll];

	[obj release];





	return 0;
}

@implementation OFThread
+ (void)initialize
{







>
>
>
>


















>
>
>
>







51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

static OFList *tlskeys;
static of_tlskey_t thread_self;

static id
call_main(id obj)
{
#ifndef OF_APPLE_RUNTIME
	objc_thread_add();
#endif

	if (!of_tlskey_set(thread_self, obj))
		@throw [OFInitializationFailedException
		    newWithClass: [obj class]];

	/*
	 * Nasty workaround for thread implementations which can't return a
	 * value on join.
	 */
	((OFThread*)obj)->retval = [[obj main] retain];

	[obj handleTermination];

	((OFThread*)obj)->running = OF_THREAD_WAITING_FOR_JOIN;

	[OFTLSKey callAllDestructors];
	[OFAutoreleasePool releaseAll];

	[obj release];

#ifndef OF_APPLE_RUNTIME
	objc_thread_remove();
#endif

	return 0;
}

@implementation OFThread
+ (void)initialize
{
204
205
206
207
208
209
210




211
212
213
214
215
216
217
		thread->running = OF_THREAD_WAITING_FOR_JOIN;
	}

	[OFTLSKey callAllDestructors];
	[OFAutoreleasePool releaseAll];

	[thread release];





	of_thread_exit();
}

- initWithObject: (id)obj
{
	self = [super init];







>
>
>
>







216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
		thread->running = OF_THREAD_WAITING_FOR_JOIN;
	}

	[OFTLSKey callAllDestructors];
	[OFAutoreleasePool releaseAll];

	[thread release];

#ifndef OF_APPLE_RUNTIME
	objc_thread_remove();
#endif

	of_thread_exit();
}

- initWithObject: (id)obj
{
	self = [super init];
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254

- (void)start
{
	if (running == OF_THREAD_RUNNING)
		@throw [OFThreadStillRunningException newWithClass: isa
							    thread: self];

	if (running = OF_THREAD_WAITING_FOR_JOIN) {
		of_thread_detach(thread);
		[retval release];
	}

	[self retain];

	if (!of_thread_new(&thread, call_main, self)) {







|







256
257
258
259
260
261
262
263
264
265
266
267
268
269
270

- (void)start
{
	if (running == OF_THREAD_RUNNING)
		@throw [OFThreadStillRunningException newWithClass: isa
							    thread: self];

	if (running == OF_THREAD_WAITING_FOR_JOIN) {
		of_thread_detach(thread);
		[retval release];
	}

	[self retain];

	if (!of_thread_new(&thread, call_main, self)) {