Skip to content

Commit ee974cc

Browse files
committed
add docs for vtr::thread_pool
1 parent 19cdc14 commit ee974cc

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

doc/src/api/vtrutil/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ VTRUTIL API
1111
container_utils
1212
logging
1313
geometry
14+
parallel
1415
other

doc/src/api/vtrutil/parallel.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=====
2+
Parallel
3+
=====
4+
5+
vtr_thread_pool
6+
-------------
7+
.. doxygenfile:: vtr_thread_pool.h
8+
:project: vtr
9+
:sections: briefdescription detaileddescription func innernamespace enum
10+
11+
.. doxygenclass:: vtr::thread_pool
12+
:project: vtr
13+
:members:

libs/libvtrutil/src/vtr_thread_pool.h

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
/**
44
* @file vtr_thread_pool.h
55
* @brief A generic thread pool for parallel task execution
6+
*
7+
* A thread pool for parallel task execution. It is a naive
8+
* implementation which uses a queue for each thread and assigns
9+
* tasks in a round robin fashion.
10+
*
11+
* Example usage:
12+
*
13+
* vtr::thread_pool pool(4);
14+
* pool.schedule_work([]{
15+
* // Task body
16+
* });
17+
* pool.wait_for_all(); // There's no API to wait for a single task
618
*/
719

820
#include <thread>
@@ -19,42 +31,29 @@
1931

2032
namespace vtr {
2133

22-
/**
23-
* A thread pool for parallel task execution. It is a naive
24-
* implementation which uses a queue for each thread and assigns
25-
* tasks in a round robin fashion.
26-
*
27-
* Example usage:
28-
*
29-
* vtr::thread_pool pool(4);
30-
* pool.schedule_work([]{
31-
* // Task body
32-
* });
33-
* pool.wait_for_all(); // There's no API to wait for a single task
34-
*/
3534
class thread_pool {
3635
private:
37-
/* Thread-local data */
36+
/** Thread-local data */
3837
struct ThreadData {
3938
std::thread thread;
40-
/* Per-thread task queue */
39+
/** Per-thread task queue */
4140
std::queue<std::function<void()>> task_queue;
4241

43-
/* Threads wait on cv for a stop signal or a new task
42+
/** Threads wait on cv for a stop signal or a new task
4443
* queue_mutex is required for condition variable */
4544
std::mutex queue_mutex;
4645
std::condition_variable cv;
4746
bool stop = false;
4847
};
4948

50-
/* Container for thread-local data */
49+
/** Container for thread-local data */
5150
std::vector<std::unique_ptr<ThreadData>> threads;
52-
/* Used for round-robin scheduling */
51+
/** Used for round-robin scheduling */
5352
std::atomic<size_t> next_thread{0};
54-
/* Used for wait_for_all */
53+
/** Used for wait_for_all */
5554
std::atomic<size_t> active_tasks{0};
5655

57-
/* Condition variable for wait_for_all */
56+
/** Condition variable for wait_for_all */
5857
std::mutex completion_mutex;
5958
std::condition_variable completion_cv;
6059

0 commit comments

Comments
 (0)