Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
ThreadPool.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/Math/Common.h"
5
7
8 /*
9 ********************************************************************************
10 *********************************** ThreadPool *********************************
11 ********************************************************************************
12 */
14 : ThreadPool{ThreadPool::Options{}}
15 {
16 }
17 inline auto ThreadPool::GetOptions () const -> Options
18 {
19 return Options{.fThreadCount = static_cast<unsigned int> (fThreads_.size ()),
20 .fThreadPoolName = fThreadPoolName_,
21 .fQMax = fDefaultQMax_,
22 .fCollectStatistics = this->fCollectStatistics_};
23 }
24 inline ThreadPool::TaskType ThreadPool::AddTask (const TaskType& task, const optional<Characters::String>& name)
25 {
26 if (fDefaultQMax_) {
27 return AddTask (task, *fDefaultQMax_, name);
28 }
29 else {
30 return AddTask_ (task, name);
31 }
32 }
34 {
35 WaitForTasksDoneUntil (tasks, Time::GetTickCount () + timeout);
36 }
37 inline void ThreadPool::WaitForTasksDone (Time::DurationSeconds timeout) const
38 {
39 WaitForTasksDoneUntil (Time::GetTickCount () + timeout);
40 }
41
42 /*
43 ********************************************************************************
44 *************************** ThreadPool::TaskInfo *******************************
45 ********************************************************************************
46 */
47 inline bool ThreadPool::TaskInfo::IsRunning () const
48 {
49 return fRunningSince.has_value ();
50 }
51
52 /*
53 ********************************************************************************
54 *************************** ThreadPool::Statistics *****************************
55 ********************************************************************************
56 */
57 inline optional<Time::DurationSeconds> ThreadPool::Statistics::GetMeanTimeConsumed () const
58 {
59 if (fNumberOfTasksReporting == 0) {
60 return nullopt;
61 }
62 return fTotalTimeConsumed / fNumberOfTasksReporting;
63 }
64
65}
chrono::duration< double > DurationSeconds
chrono::duration<double> - a time span (length of time) measured in seconds, but high precision.
Definition Realtime.h:57
nonvirtual TaskType AddTask(const TaskType &task, const optional< Characters::String > &name=nullopt)
nonvirtual void WaitForTasksDoneUntil(const Traversal::Iterable< TaskType > &tasks, Time::TimePointSeconds timeoutAt) const
nonvirtual void WaitForTasksDone(const Traversal::Iterable< TaskType > &tasks, Time::DurationSeconds timeout=Time::kInfinity) const
nonvirtual Options GetOptions() const
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
Definition Iterable.h:237
nonvirtual size_t size() const
Returns the number of items contained.
Definition Iterable.inl:300