ObjFW  Check-in [e1b8152dd9]

Overview
Comment:Merge a few changes from default branch to 0.5 branch.

Changesets:
* 8a0cee0e7fb2
* e9f5dda18648
* 38b1ce72bd0b
* c09dc6f82884
* e193cd04a3df

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | 0.5
Files: files | file ages | folders
SHA3-256: e1b8152dd9340884ab02be9afe66e83ac363eb8cb46c3d064e178b98460e75d4
User & Date: js on 2011-04-21 11:19:32
Other Links: branch diff | manifest | tags
Context
2011-04-21
11:21
Update ChangeLog. check-in: 24c4b1a4fd user: js tags: 0.5, 0.5.1-release
11:19
Merge a few changes from default branch to 0.5 branch. check-in: e1b8152dd9 user: js tags: 0.5
2011-04-10
18:07
Update ChangeLog. check-in: 84eb9249b4 user: js tags: 0.5
Changes

Modified src/OFThread.m from [fd76b79d25] to [926b087d59].

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)
{
#if defined(OF_GNU_RUNTIME) || defined(OF_OLD_GNU_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];

#if defined(OF_GNU_RUNTIME) || defined(OF_OLD_GNU_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];

#if defined(OF_GNU_RUNTIME) || defined(OF_OLD_GNU_RUNTIME)
	objc_thread_remove();
#endif

	of_thread_exit();
}

- initWithObject: (id)obj
{
	self = [super init];
239
240
241
242
243
244
245





246
247
248
249
250
251
252
}

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






	[self retain];

	if (!of_thread_new(&thread, call_main, self)) {
		[self release];
		@throw [OFThreadStartFailedException newWithClass: isa
							   thread: self];







>
>
>
>
>







255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
}

- (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)) {
		[self release];
		@throw [OFThreadStartFailedException newWithClass: isa
							   thread: self];
268
269
270
271
272
273
274







275
276
277
278
279
280
281

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








	[object release];
	[retval release];

	[super dealloc];
}
@end








>
>
>
>
>
>
>







289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309

- (void)dealloc
{
	if (running == OF_THREAD_RUNNING)
		@throw [OFThreadStillRunningException newWithClass: isa
							    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);

	[object release];
	[retval release];

	[super dealloc];
}
@end

Modified src/threading.h from [ad9f8119e0] to [ed61fa08de].

86
87
88
89
90
91
92











93
94
95
96
97
98
99
		return NO;

	CloseHandle(thread);

	return YES;
#endif
}












static OF_INLINE void
of_thread_exit()
{
#if defined(OF_HAVE_PTHREADS)
	pthread_exit(NULL);
#elif defined(_WIN32)







>
>
>
>
>
>
>
>
>
>
>







86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
		return NO;

	CloseHandle(thread);

	return YES;
#endif
}

static OF_INLINE BOOL
of_thread_detach(of_thread_t thread)
{
#if defined(OF_HAVE_PTHREADS)
	return !pthread_detach(thread);
#elif defined(_WIN32)
	/* FIXME */
	return YES;
#endif
}

static OF_INLINE void
of_thread_exit()
{
#if defined(OF_HAVE_PTHREADS)
	pthread_exit(NULL);
#elif defined(_WIN32)