ObjFW
OFThreadPool.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #import "OFObject.h"
17 
18 OF_ASSUME_NONNULL_BEGIN
19 
22 #ifdef OF_HAVE_BLOCKS
26 typedef void (^of_thread_pool_block_t)(void);
27 #endif
28 
29 @class OFCondition;
30 @class OFList OF_GENERIC(ObjectType);
31 @class OFMutableArray OF_GENERIC(ObjectType);
32 @class OFThreadPoolJob;
33 
42 OF_SUBCLASSING_RESTRICTED
44 {
45  size_t _size;
46  OFMutableArray *_threads;
47  volatile int _count;
48 #ifdef OF_THREAD_POOL_M
49 @public
50 #endif
51  OFList *_queue;
52  OFCondition *_queueCondition;
53  volatile int _doneCount;
54  OFCondition *_countCondition;
55 }
56 
60 @property (readonly, nonatomic) size_t size;
61 
70 + (instancetype)threadPool;
71 
78 + (instancetype)threadPoolWithSize: (size_t)size;
79 
87 - (instancetype)initWithSize: (size_t)size OF_DESIGNATED_INITIALIZER;
88 
97 - (void)dispatchWithTarget: (id)target
98  selector: (SEL)selector
99  object: (nullable id)object;
100 
101 #ifdef OF_HAVE_BLOCKS
107 - (void)dispatchWithBlock: (of_thread_pool_block_t)block;
108 #endif
109 
113 - (void)waitUntilDone;
114 @end
115 
116 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:26
A class implementing a condition variable for thread synchronization.
Definition: OFCondition.h:31
A class which provides easy to use double-linked lists.
Definition: OFList.h:55
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:44
The root class for all other classes inside ObjFW.
Definition: OFObject.h:520
A class providing a pool of reusable threads.
Definition: OFThreadPool.h:44