ObjFW
OFThreadPool.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
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 OF_ASSUME_NONNULL_BEGIN
20 
23 #ifdef OF_HAVE_BLOCKS
24 
27 typedef void (^of_thread_pool_block_t)(void);
28 #endif
29 
30 #ifndef DOXYGEN
31 @class OFMutableArray OF_GENERIC(ObjectType);
32 @class OFList OF_GENERIC(ObjectType);
33 #endif
34 @class OFCondition;
35 @class OFThreadPoolJob;
36 
46 {
47  size_t _size;
48  OFMutableArray *_threads;
49  volatile int _count;
50 @public
51  OFList *_queue;
52  OFCondition *_queueCondition;
53  volatile int _doneCount;
54  OFCondition *_countCondition;
55 }
56 
65 + (instancetype)threadPool;
66 
76 + (instancetype)threadPoolWithSize: (size_t)size;
77 
88 - initWithSize: (size_t)size;
89 
98 - (void)dispatchWithTarget: (id)target
99  selector: (SEL)selector
100  object: (nullable id)object;
101 
102 #ifdef OF_HAVE_BLOCKS
103 
108 - (void)dispatchWithBlock: (of_thread_pool_block_t)block;
109 #endif
110 
114 - (void)waitUntilDone;
115 
121 - (size_t)size;
122 @end
123 
124 OF_ASSUME_NONNULL_END
void(^ of_thread_pool_block_t)(void)
A block for a job which should be executed in a thread pool.
Definition: OFThreadPool.h:27
The root class for all other classes inside ObjFW.
Definition: OFObject.h:364
A class providing a pool of reusable threads.
Definition: OFThreadPool.h:45
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:46
A class which provides easy to use double-linked lists.
Definition: OFList.h:53
A class implementing a condition variable for thread synchronization.
Definition: OFCondition.h:28