Skip to content

Commit 52f60a3

Browse files
committed
Update internal docs
1 parent 3b5e46a commit 52f60a3

4 files changed

Lines changed: 18 additions & 17 deletions

File tree

include/dispatch_queue.hpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ namespace dispatch_queue {
1313
class dispatch_queue {
1414
public:
1515
/**
16-
* Create a synchronous dispatch queue.
17-
* In synchronous mode, tasks are executed immediately when calling `dispatch`.
16+
* Create an immediate dispatch queue.
17+
* In immediate mode, tasks are executed immediately when calling `dispatch`.
1818
*/
1919
dispatch_queue();
2020

@@ -28,12 +28,12 @@ class dispatch_queue {
2828
* Initializes dispatch queue with `thread_count` background threads and a worker initialization functor.
2929
*
3030
* @param thread_count Number of background threads used to run tasks.
31-
* If 0, the dispatch queue is created in synchronous mode.
31+
* If 0, the dispatch queue is created in immediate mode.
3232
* If 1, tasks will run serially in background, one at a time, without any concurrency.
3333
* Otherwise, `thread_count` threads will be created and tasks may run concurrently.
3434
* Pass a negative number to use the default value of `std::thread::hardware_concurrency()` threads.
3535
* @param worker_init Functor called inside worker threads for initialization, receiving as argument the worker index.
36-
* May be used to set the thread name, for example.
36+
* May be used to set the thread name or initialize thread local variables, for example.
3737
*/
3838
template<typename Fn>
3939
dispatch_queue(int thread_count, Fn&& worker_init) {
@@ -55,7 +55,7 @@ class dispatch_queue {
5555

5656
/**
5757
* Dispatch a task that calls `f` with forwarded arguments `args`.
58-
* If the dispatch queue is in synchronous mode, the task is processed immediately in the calling thread.
58+
* If the dispatch queue is in immediate mode, the task is processed immediately in the calling thread.
5959
* @param f Functor to be executed
6060
* @param args Arguments forwarded to `f`
6161
* @returns Future for getting `f` result.
@@ -71,6 +71,7 @@ class dispatch_queue {
7171
* @param f Functor to be executed
7272
* @param args Arguments forwarded to `f`
7373
* @returns Future for getting `f` result.
74+
* @see main_loop
7475
*/
7576
template<typename F, typename... Args, typename Ret = detail::function_result<F, Args...>>
7677
task<Ret> dispatch_main(F&& f, Args&&... args) {
@@ -84,7 +85,7 @@ class dispatch_queue {
8485

8586
/**
8687
* Number of threads used for processing tasks.
87-
* This will be 0 on synchronous mode.
88+
* This will be 0 in immediate mode.
8889
*/
8990
int thread_count() const;
9091

@@ -106,7 +107,7 @@ class dispatch_queue {
106107

107108
/**
108109
* Invoke main loop tasks dispatched using `dispatch_main`.
109-
* This should be called in you application main loop.
110+
* This should be called in your application's main loop.
110111
*/
111112
void main_loop();
112113

@@ -118,7 +119,7 @@ class dispatch_queue {
118119
/**
119120
* Wait until all pending tasks finish processing.
120121
* Blocks until specified `timeout_duration` has elapsed or all queued tasks complete, whichever comes first.
121-
* @returns `false` if the timeout has expired, otherwise `true`.
122+
* @returns `true` if all tasks finished processing, otherwise `false`.
122123
*/
123124
template<class Rep, class Period>
124125
bool wait_for(const std::chrono::duration<Rep, Period>& timeout_duration) {
@@ -133,7 +134,7 @@ class dispatch_queue {
133134
/**
134135
* Wait until all pending tasks finish processing.
135136
* Blocks until the specified `timeout_time` has been reached or all queued tasks complete, whichever comes first.
136-
* @returns `false` if the timeout has expired, otherwise `true`.
137+
* @returns `true` if all tasks finished processing, otherwise `false`.
137138
*/
138139
template<class Clock, class Duration>
139140
bool wait_until(const std::chrono::time_point<Clock, Duration>& timeout_time) {
@@ -146,8 +147,8 @@ class dispatch_queue {
146147
}
147148

148149
/**
149-
* Cancel pending tasks, wait and release the used Threads.
150-
* The queue now runs in synchronous mode.
150+
* Cancel pending tasks, wait and release the used threads.
151+
* The queue now runs in immediate mode.
151152
* It is safe to call this more than once.
152153
*/
153154
void shutdown();

include/task.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class task {
3333
* Add a continuation `f` that is guaranteed to run after this task finishes.
3434
*
3535
* If the task is not finished yet, `f` will run right after the task finishes in the same thread where the task ran.
36-
* Otherwise, `f` will run immediately in the current thread.
36+
* Otherwise, `f` will run immediately in the calling thread.
3737
*/
3838
template<typename F>
3939
requires (detail::is_instance_of<T, task>::value)
@@ -53,7 +53,7 @@ class task {
5353
* Add a continuation `f` that is guaranteed to run after this task finishes.
5454
*
5555
* If the task is not finished yet, `f` will run right after the task finishes in the same thread where the task ran.
56-
* Otherwise, `f` will run immediately in the current thread.
56+
* Otherwise, `f` will run immediately in the calling thread.
5757
*/
5858
template<typename F>
5959
auto then(F&& f) const {
@@ -102,7 +102,7 @@ class task {
102102
* If the task is pending (`get_state() == task_state::pending`), blocks until task finishes or until the specified `timeout_duration` has elapsed.
103103
* Otherwise returns immediately without blocking.
104104
*
105-
* @returns `false` if the timeout has expired, otherwise `true`.
105+
* @returns `true` if the task is finished, otherwise `false`.
106106
*/
107107
template<class Rep, class Period>
108108
bool wait_for(const std::chrono::duration<Rep, Period>& timeout_duration) const {
@@ -115,7 +115,7 @@ class task {
115115
* If the task is pending (`get_state() == task_state::pending`), blocks until task finishes or until the specified `timeout_time` has been reached.
116116
* Otherwise returns immediately without blocking.
117117
*
118-
* @returns `false` if the timeout has expired, otherwise `true`.
118+
* @returns `true` if the task is finished, otherwise `false`.
119119
*/
120120
template<class Clock, class Duration>
121121
bool wait_until(const std::chrono::time_point<Clock, Duration>& timeout_time) const {
@@ -162,6 +162,7 @@ class task {
162162
private:
163163
std::shared_ptr<detail::task_future<T>> future;
164164

165+
/// Helper function for creating a task of another type from within this class
165166
template<typename U>
166167
static task<U> to_task(std::shared_ptr<detail::task_future<U>> future) {
167168
return task<U>(future);

include/task_future.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace dispatch_queue {
1414
enum class task_state {
1515
/// Task is either queued for execution or still running
1616
pending,
17-
/// Task is ready and the result value is readily available
17+
/// Task finished successfully and the result value is readily available
1818
ready,
1919
/// Task failed with an exception
2020
failed,

src/dispatch_queue.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace dispatch_queue {
44

55
dispatch_queue::dispatch_queue()
6-
: dispatch_queue(0)
76
{
87
}
98

0 commit comments

Comments
 (0)