18#if ALIB_DEBUG && !DOXYGEN
19 namespace{
unsigned int initFlag= 0; }
26 ALIB_ASSERT_ERROR( initFlag == 0,
"ENUMS",
"This method must not be invoked twice." )
32 { Priority::Lowest ,
A_CHAR(
"Lowest" ), 4 },
33 { Priority::DeferredDeletion,
A_CHAR(
"DeferredDeletion" ), 1 },
34 { Priority::Low ,
A_CHAR(
"Low" ), 1 },
35 { Priority::Standard ,
A_CHAR(
"Standard" ), 1 },
36 { Priority::Highest ,
A_CHAR(
"Highest" ), 5 },
37 { Priority::High ,
A_CHAR(
"High" ), 1 },
56 #if ALIB_DEBUG_CRITICAL_SECTIONS
78 <<
"\"to remove not found ")
89 int nextWarnSecond= 1;
94 if( waitCheck.
Age().InAbsoluteSeconds() == nextWarnSecond )
97 << thread.
GetName() <<
"\" to stop. "
99 <<
", Load: " << thread.
Load() )
112 ALIB_DBG(, Ticks::Duration dbgWarnAfter) )
127 if( cntRunning == 0 )
131 if( nextWarning.Age() > dbgWarnAfter)
134 dbgThreadList <<
"Waiting on " << cntRunning <<
" thread(s) to become idle:\n";
138 if ( it->Load() > 0 )
139 dbgThreadList << ++tNr <<
": " << it->GetName()
140 <<
",\tState::" << it->state
141 <<
",\t Load: " << it->Load() <<
NEW_LINE;
149 if (waitStart.
Age() > timeout)
162 int nextWarnSecond= 1; )
166 if( !it->StopIsScheduled() )
167 it->ScheduleStop( stopPriority );
178 if( cntRunning == 0 )
183 if( waitCheck.Age().InAbsoluteSeconds() == nextWarnSecond )
185 NString4K dbgThreadList(
"DWManager Termination: Waiting on " );
186 dbgThreadList << cntRunning <<
" Threads to stop. List of threads: " <<
NEW_LINE;
190 dbgThreadList << ++tNr <<
": " << it->GetName()
191 <<
",\tState::" << it->state
192 <<
",\t Load: " << it->Load() <<
NEW_LINE;
214 auto it=
queue.begin();
215 while(it !=
queue.end())
217 if(jobInfo.priority <= it->priority )
223 queue.Insert(it, jobInfo );
226 "Queue(" <<
queue.Count() <<
") "
227 "Job(" << jobInfo.job->ID <<
") pushed. "
228 "P::" << jobInfo.priority <<
", "
229 "Keep: " << jobInfo.keepJob )
243 std::pair<Job*, bool> result= {
queue.Back().job,
queue.Back().keepJob };
250 "Queue(" <<
length <<
") "
251 "Job(" << result.first->ID <<
") popped. "
252 "P::" << dbgPriority <<
", "
253 "Keep: " << result.second )
265 auto jobInfo =
pop();
275 auto size= job.JobToDelete->SizeOf();
276 job.JobToDelete->~Job();
290 if (jobInfo.first->Is<
JobStop>() )
300 if ( jobInfo.first->Do() )
303 if ( !jobInfo.second )
305 auto size= jobInfo.first->SizeOf();
306 jobInfo.first->~Job();
315 "Job of type <" << jobInfo.first->ID <<
">"
316 "passed to DedicatedWorker, which was neither recognized by\n"
317 "the specialist nor has it a Job::Do() implementation!" )
324 "DedicatedWorker \"" <<
GetName() <<
"\" has " <<
Load() <<
325 " jobs still queued when stopped!\n" )
328 "DedicatedWorker \"" <<
GetName() <<
"\" is stopping (leaving method Run())." )
lang::Placeholder< lang::DbgCriticalSections > DbgCriticalSectionsPH
void free(void *mem, size_t size)
constexpr const TChar * Terminate() const
ALIB_API bool WaitForAllIdle(Ticks::Duration timeout, Ticks::Duration dbgWarnAfter)
PoolAllocator & GetPoolAllocator()
List< MonoAllocator, DedicatedWorker * > workers
The list of workers.
MonoAllocator ma
Mono allocator. Used for commands and by DedicatedWorkers.
ALIB_API void Add(DedicatedWorker &thread)
ALIB_API void RemoveAll(Priority stopPriority=Priority::Lowest)
ALIB_API bool Remove(DedicatedWorker &thread, Priority stopPriority=Priority::Lowest)
ALIB_API DWManager()
Constructor.
List< HeapAllocator, QueueElement > queue
virtual ALIB_API void Run() override
void ScheduleStop(Priority priority)
virtual bool process(Job &vjob)
ALIB_API void pushAndRelease(QueueElement &&jobInfo)
virtual const CString GetName() const
bool stopJobExecuted
Flag which is set when the stop-job was executed.
DWManager & manager
needed as we inherit TCondition
std::pair< Job *, bool > pop()
int length
The current number of jobs in the queue.
alib::Ticks statLastJobExecution
DbgLockAsserter Dbg
The debug tool instance.
virtual ALIB_API void Start()
@ Terminated
The thread is terminated.
static void SleepMicros(int64_t microseconds)
virtual ALIB_API void Join()
#define ALIB_WARNING(...)
#define ALIB_MESSAGE(...)
#define ALIB_ASSERT_ERROR(cond,...)
#define ALIB_ASSERT_WARNING(cond,...)
#define ALIB_CALLER_PRUNED
#define ALIB_LOCK_WITH(lock)
#define ALIB_ASSERT(cond)
ALIB_API void Bootstrap()
Priority
Possible priorities of jobs assigned to an DedicatedWorker.
NLocalString< 256 > NString256
Type alias name for TLocalString<nchar,256>.
constexpr CString NEW_LINE
A zero-terminated string containing the new-line character sequence.
NLocalString< 512 > NString512
Type alias name for TLocalString<nchar,512>.
NLocalString< 4096 > NString4K
Type alias name for TLocalString<nchar,8192>.
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)