ObjFW  Check-in [663f63e55a]

Overview
Comment:There was no real reason to rename -[main] to -[run]. Undo it.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 663f63e55af7a2b7ad6a0160d79ba4b594dea59677282439eb5cc59e31d5ca6c
User & Date: js on 2010-04-10 22:33:03
Other Links: manifest | tags
Context
2010-04-10
23:10
Prevent starting a thread twice. check-in: 8135be3b0f user: js tags: trunk
22:33
There was no real reason to rename -[main] to -[run]. Undo it. check-in: 663f63e55a user: js tags: trunk
22:06
Add +[yield] to OFThread. check-in: 1adf3bb9bf user: js tags: trunk
Changes

Modified src/OFThread.h from [ca016b6bde] to [f1900f7431].

127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
 * \param obj An object that is passed to the main method as a copy or nil
 * \return An initialized OFThread.
 */
- initWithObject: (OFObject <OFCopying>*)obj;

/**
 * The run routine of the thread. You need to reimplement this!
 *
 * It can access the object passed to the threadWithObject or initWithObject
 * method using the instance variable named object.
 *
 * \return The object the join method should return when called for this thread
 */
- (id)run;

/**
 * This routine is exectued when the thread's run method has finished executing
 * or terminate has been called.
 */
- (void)handleTermination;

/**
 * Starts the thread.
 */







|






|


|







127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
 * \param obj An object that is passed to the main method as a copy or nil
 * \return An initialized OFThread.
 */
- initWithObject: (OFObject <OFCopying>*)obj;

/**
 * The main routine of the thread. You need to reimplement this!
 *
 * It can access the object passed to the threadWithObject or initWithObject
 * method using the instance variable named object.
 *
 * \return The object the join method should return when called for this thread
 */
- (id)main;

/**
 * This routine is exectued when the thread's main method has finished executing
 * or terminate has been called.
 */
- (void)handleTermination;

/**
 * Starts the thread.
 */

Modified src/OFThread.m from [6abaf9455e] to [935cd4400e].

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

#import "threading.h"

static OFList *tlskeys;
static of_tlskey_t thread_self;

static id
call_run(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 run] retain];

	[obj handleTermination];

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

	[OFTLSKey callAllDestructors];
	[OFAutoreleasePool releaseAll];







|









|







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

#import "threading.h"

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];
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
	self = [super init];

	object = [obj retain];

	return self;
}

- (id)run
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];

	return nil;
}

- (void)handleTermination
{
}

- start
{
	[self retain];

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

	running = OF_THREAD_RUNNING;

	return self;







|















|







146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
	self = [super init];

	object = [obj retain];

	return self;
}

- (id)main
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];

	return nil;
}

- (void)handleTermination
{
}

- start
{
	[self retain];

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

	running = OF_THREAD_RUNNING;

	return self;

Modified tests/OFThreadTests.m from [1c2bd09aff] to [167800b2db].

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

static OFString *module = @"OFThread";

@interface TestThread: OFThread
@end

@implementation TestThread
- (id)run
{
	if ([object isEqual: @"foo"])
		return @"success";

	return nil;
}
@end







|







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

static OFString *module = @"OFThread";

@interface TestThread: OFThread
@end

@implementation TestThread
- (id)main
{
	if ([object isEqual: @"foo"])
		return @"success";

	return nil;
}
@end