ObjFW  Diff

Differences From Artifact [9c891bd73d]:

To Artifact [1c5160c994]:


21
22
23
24
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

50
51
52

53
54
55
56
57


58
59

60
61
62
63


64
65
66
67
68


69
70
71

72
73
74

75
76
77
78
79
80


81
82
83

84
85
86
87


88
89
90
91
92


93
94
95
96
97



98
99
100
101
102
103
104
105


106
107

108
109
110
111
112
113


114
115
116
117
118


119
120

121
122
123
21
22
23
24
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
50
51

52
53
54
55


56
57
58

59
60
61


62
63
64
65
66


67
68
69
70

71
72
73

74
75
76
77
78


79
80
81
82

83
84
85


86
87
88
89
90


91
92
93
94



95
96
97
98
99
100
101
102
103


104
105
106

107
108
109
110
111


112
113
114
115
116


117
118
119

120
121
122
123







-
-
+
+

-
+














-
-
+
+

-
+


-
+



-
-
+
+

-
+


-
-
+
+



-
-
+
+


-
+


-
+




-
-
+
+


-
+


-
-
+
+



-
-
+
+


-
-
-
+
+
+






-
-
+
+

-
+




-
-
+
+



-
-
+
+

-
+



#endif

@class OFMutableArray;
@class OFList;
@class OFCondition;
@class OFThreadPoolJob;

/**
 * \brief A class providing a pool of reusable threads.
/*!
 * @brief A class providing a pool of reusable threads.
 *
 * \note When the thread pool is released, all threads will terminate after
 * @note When the thread pool is released, all threads will terminate after
 *	 they finish the job they are currently processing.
 */
@interface OFThreadPool: OFObject
{
	size_t size;
	OFMutableArray *threads;
	volatile int count;
@public
	OFList *queue;
	OFCondition *queueCondition;
	volatile int doneCount;
	OFCondition *countCondition;
}

/**
 * \brief Returns a new thread pool with one thread for each core in the system.
/*!
 * @brief Returns a new thread pool with one thread for each core in the system.
 *
 * \warning If for some reason the number of cores in the system could not be
 * @warning If for some reason the number of cores in the system could not be
 *	    determined, the pool will only have one thread!
 *
 * \return A new thread pool with one thread for each core in the system
 * @return A new thread pool with one thread for each core in the system
 */
+ (instancetype)threadPool;

/**
 * \brief Returns a new thread pool with the specified number of threads.
/*!
 * @brief Returns a new thread pool with the specified number of threads.
 *
 * \warning If for some reason the number of cores in the system could not be
 * @warning If for some reason the number of cores in the system could not be
 *	    determined, the pool will only have one thread!
 *
 * \param size The number of threads for the pool
 * \return A new thread pool with the specified number of threads
 * @param size The number of threads for the pool
 * @return A new thread pool with the specified number of threads
 */
+ (instancetype)threadPoolWithSize: (size_t)size;

/**
 * \brief Initializes an already allocated OFThreadPool with one thread for
/*!
 * @brief Initializes an already allocated OFThreadPool with one thread for
 *	  each core in the system.
 *
 * \warning If for some reason the number of cores in the system could not be
 * @warning If for some reason the number of cores in the system could not be
 *	    determined, the pool will only have one thread!
 *
 * \return An initialized OFThreadPool with one thread for each core in the
 * @return An initialized OFThreadPool with one thread for each core in the
 *	   system
 */
- init;

/**
 * \brief Initializes an already allocated OFThreadPool with the specified
/*!
 * @brief Initializes an already allocated OFThreadPool with the specified
 *	  number of threads.
 *
 * \warning If for some reason the number of cores in the system could not be
 * @warning If for some reason the number of cores in the system could not be
 *	    determined, the pool will only have one thread!
 *
 * \param size The number of threads for the pool
 * \return An initialized OFThreadPool with the specified number of threads
 * @param size The number of threads for the pool
 * @return An initialized OFThreadPool with the specified number of threads
 */
- initWithSize: (size_t)size;

/**
 * \brief Execute the specified selector on the specified target with the
/*!
 * @brief Execute the specified selector on the specified target with the
 *	  specified object as soon as a thread is ready.
 *
 * \param target The target on which to perform the selector
 * \param selector The selector to perform on the target
 * \param object THe object with which the selector is performed on the target
 * @param target The target on which to perform the selector
 * @param selector The selector to perform on the target
 * @param object THe object with which the selector is performed on the target
 */
- (void)dispatchWithTarget: (id)target
		  selector: (SEL)selector
		    object: (id)object;

#ifdef OF_HAVE_BLOCKS
/**
 * \brief Executes the specified block as soon as a thread is ready.
/*!
 * @brief Executes the specified block as soon as a thread is ready.
 *
 * \param block The block to execute
 * @param block The block to execute
 */
- (void)dispatchWithBlock: (of_thread_pool_block_t)block;
#endif

/**
 * \brief Waits until all jobs are done.
/*!
 * @brief Waits until all jobs are done.
 */
- (void)waitUntilDone;

/**
 * \brief Returns the size of the thread pool.
/*!
 * @brief Returns the size of the thread pool.
 *
 * \return The size of the thread pool
 * @return The size of the thread pool
 */
- (size_t)size;
@end