︙ | | |
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
-
+
-
+
|
OF_DIRECT_MEMBERS
@interface OFThreadPoolJob: OFObject
{
id _target;
SEL _selector;
id _object;
#ifdef OF_HAVE_BLOCKS
of_thread_pool_block_t _block;
OFThreadPoolBlock _block;
#endif
}
- (instancetype)initWithTarget: (id)target
selector: (SEL)selector
object: (id)object;
#ifdef OF_HAVE_BLOCKS
- (instancetype)initWithBlock: (of_thread_pool_block_t)block;
- (instancetype)initWithBlock: (OFThreadPoolBlock)block;
#endif
- (void)perform;
@end
@implementation OFThreadPoolJob
- (instancetype)initWithTarget: (id)target
selector: (SEL)selector
|
︙ | | |
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
-
+
|
@throw e;
}
return self;
}
#ifdef OF_HAVE_BLOCKS
- (instancetype)initWithBlock: (of_thread_pool_block_t)block
- (instancetype)initWithBlock: (OFThreadPoolBlock)block
{
self = [super init];
@try {
_block = [block copy];
} @catch (id e) {
[self release];
|
︙ | | |
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
-
+
-
+
-
+
-
+
-
-
+
+
|
pool = objc_autoreleasePoolPush();
for (;;) {
OFThreadPoolJob *job;
[_queueCondition lock];
@try {
of_list_object_t *listObject;
OFListItem listItem;
if (_terminate) {
objc_autoreleasePoolPop(pool);
return nil;
}
listObject = _queue.firstListObject;
listItem = _queue.firstListItem;
while (listObject == NULL) {
while (listItem == NULL) {
[_queueCondition wait];
if (_terminate) {
objc_autoreleasePoolPop(pool);
return nil;
}
listObject = _queue.firstListObject;
listItem = _queue.firstListItem;
}
job = [[listObject->object retain] autorelease];
[_queue removeListObject: listObject];
job = [[OFListItemObject(listItem) retain] autorelease];
[_queue removeListItem: listItem];
} @finally {
[_queueCondition unlock];
}
if (_terminate) {
objc_autoreleasePoolPop(pool);
return nil;
|
︙ | | |
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
-
+
|
[self of_dispatchJob: job];
} @finally {
[job release];
}
}
#ifdef OF_HAVE_BLOCKS
- (void)dispatchWithBlock: (of_thread_pool_block_t)block
- (void)dispatchWithBlock: (OFThreadPoolBlock)block
{
OFThreadPoolJob *job = [[OFThreadPoolJob alloc] initWithBlock: block];
@try {
[self of_dispatchJob: job];
} @finally {
[job release];
}
|
︙ | | |