8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
43 #if ALIB_DEBUG_CRITICAL_SECTIONS
44 ma.DbgCriticalSectionsPH.Get()->DCSLock=
this;
75 int nextWarnSecond= 1;
80 if( waitCheck.
Age().InAbsoluteSeconds() == nextWarnSecond )
83 "DWManager::Remove: Waiting on thread \"{}\" to stop. State::{}, Load: ",
97 ALIB_DBG(, Ticks::Duration dbgWarnAfter) )
112 if( cntRunning == 0 )
116 if( nextWarning.Age() > dbgWarnAfter)
118 std::vector<std::any> args; args.reserve(32);
119 args.emplace_back(
"Waiting on {} thread(s) to become idle.\n");
120 args.emplace_back( cntRunning );
124 if ( it->Load() > 0 ) {
125 args.emplace_back( ++tNr );
126 args.emplace_back(
": {},\tState::{},\t Load: \n" );
127 args.emplace_back( it->GetName() );
128 args.emplace_back( it->state );
129 args.emplace_back( it->Load() );
138 if (waitStart.
Age() > timeout)
151 int nextWarnSecond= 1; )
155 if( !it->StopIsScheduled() )
156 it->ScheduleStop( stopPriority );
167 if( cntRunning == 0 )
172 if( waitCheck.Age().InAbsoluteSeconds() == nextWarnSecond )
174 std::vector<std::any> args; args.reserve(32);
175 args.emplace_back(
"DWManager Termination: Waiting on {} thread(s) to stop.\n");
176 args.emplace_back( cntRunning );
180 args.emplace_back( ++tNr );
181 args.emplace_back(
": {},\tState::{},\t Load: \n" );
182 args.emplace_back( it->GetName() );
183 args.emplace_back( it->state );
184 args.emplace_back( it->Load() );
206 auto it=
queue.begin();
207 while(it !=
queue.end())
209 if(jobInfo.priority <= it->priority )
215 queue.Insert(it, jobInfo );
218 std::vector<std::any> args; args.reserve(32);
219 args.emplace_back(
"Queue({}) Job({}) pushed. P::{} Keep: ");
220 args.emplace_back(
queue.size() );
221 args.emplace_back( &jobInfo.job->ID );
222 args.emplace_back( jobInfo.priority );
223 args.emplace_back( jobInfo.keepJob );
239 std::pair<Job*, bool> result= {
queue.back().job,
queue.back().keepJob };
246 std::vector<std::any> args; args.reserve(32);
247 args.emplace_back(
"Queue({}) Job({}) pushed. P::{} Keep: ");
248 args.emplace_back(
length );
249 args.emplace_back( &result.first->ID );
250 args.emplace_back( dbgPriority );
251 args.emplace_back( result.second );
264 auto jobInfo =
pop();
274 auto size= job.JobToDelete->SizeOf();
275 job.JobToDelete->~Job();
276 manager.GetPoolAllocator().free( job.JobToDelete, size );
289 if (jobInfo.first->Is<
JobStop>() )
294 manager.GetPoolAllocator().free( jobInfo.first,
sizeof(
JobStop) );
299 if ( jobInfo.first->Do() )
302 if ( !jobInfo.second )
304 auto size= jobInfo.first->SizeOf();
305 jobInfo.first->~Job();
306 manager.GetPoolAllocator().free( jobInfo.first, size );
314 "Job of type <{}> passed to DedicatedWorker, which was neither recognized by\n"
315 "the specialist nor has it a Job::Do() implementation!", &jobInfo.first->ID )
322 "DedicatedWorker \"{}\" has jobs still queued when stopped!",
GetName(),
Load() )
324 ALIB_MESSAGE(
"MGTHR",
"DedicatedWorker \"{}\" is stopping (leaving method Run()).",
GetName() )
MonoAllocator ma
Mono allocator. Used for commands and by DedicatedWorkers.
ALIB_DLL void RemoveAll(Priority stopPriority=Priority::Lowest)
ALIB_DLL DWManager()
Constructor.
ALIB_DLL void Add(DedicatedWorker &thread)
ALIB_DLL bool Remove(DedicatedWorker &thread, Priority stopPriority=Priority::Lowest)
PoolAllocator pool
Pool allocator. Used for command objects.
List< MonoAllocator, DedicatedWorker * > workers
The list of workers.
ALIB_DLL bool WaitForAllIdle(Ticks::Duration timeout, Ticks::Duration dbgWarnAfter)
virtual ALIB_DLL void Run() override
virtual bool process(Job &vjob)
std::pair< Job *, bool > pop()
ALIB_DLL void pushAndRelease(QueueElement &&jobInfo)
DWManager & manager
needed as we inherit TCondition
int length
The current number of jobs in the queue.
List< HeapAllocator, QueueElement > queue
bool stopJobExecuted
Flag which is set when the stop-job was executed.
void ScheduleStop(Priority priority)
alib::Ticks statLastJobExecution
virtual const character * GetName() const
DbgLockAsserter Dbg
The debug tool instance.
@ Terminated
The thread is terminated.
static void SleepMicros(int64_t microseconds)
virtual ALIB_DLL void Start()
virtual ALIB_DLL void Join()
#define ALIB_MESSAGE(domain,...)
#define ALIB_ASSERT(cond, domain)
#define ALIB_WARNING(domain,...)
#define ALIB_ASSERT_WARNING(cond, domain,...)
#define ALIB_ERROR(domain,...)
#define ALIB_ASSERT_ERROR(cond, domain,...)
#define ALIB_CALLER_PRUNED
#define ALIB_LOCK_WITH(lock)
void raise(const CallerInfo &ci, int type, std::string_view domain, const std::span< std::any > &args)
Priority
Possible priorities of jobs assigned to an DedicatedWorker.
time::Ticks Ticks
Type alias in namespace alib.
The job sent by method DeleteJobDeferred.
Job * JobToDelete
The job to be deleted.
The stop job sent by method ScheduleStop.
Container element of the queue.
virtual void PrepareDeferredDeletion()
void WaitForNotification(ALIB_DBG_TAKE_CI)
void Acquire(ALIB_DBG_TAKE_CI)
void ReleaseAndNotify(ALIB_DBG_TAKE_CI)