ObjFW
 All Classes Functions Variables
OFThreadPool.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012
3  * Jonathan Schleifer <js@webkeks.org>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #import "OFObject.h"
18 
19 #ifdef OF_HAVE_BLOCKS
20 typedef void (^of_thread_pool_block_t)(void);
21 #endif
22 
23 @class OFMutableArray;
24 @class OFList;
25 @class OFCondition;
26 @class OFThreadPoolJob;
27 
35 {
36  size_t size;
37  OFMutableArray *threads;
38  volatile int count;
39 @public
40  OFList *queue;
41  OFCondition *queueCondition;
42  volatile int doneCount;
43  OFCondition *countCondition;
44 }
45 
54 + (instancetype)threadPool;
55 
65 + (instancetype)threadPoolWithSize: (size_t)size;
66 
77 - init;
78 
89 - initWithSize: (size_t)size;
90 
99 - (void)dispatchWithTarget: (id)target
100  selector: (SEL)selector
101  object: (id)object;
102 
103 #ifdef OF_HAVE_BLOCKS
104 
109 - (void)dispatchWithBlock: (of_thread_pool_block_t)block;
110 #endif
111 
115 - (void)waitUntilDone;
116 
122 - (size_t)size;
123 @end