9#if !defined(HPP_AWORX_ALIB_THREADS_MODEL_MTHREAD)
13# if !defined(HPP_ALIB_ENUMS_SERIALIZATION)
21namespace alib::threads::model {
23MThread::MThread(
const String& pName)
31 State curState= GetState();
32 if( curState == Thread::State::Unstarted )
35 <<
"\" is destructed, while it was never started" )
37 else if( curState != Thread::State::Terminated )
40 <<
"\" is destructed, while it is in state \""
49 cmdPipe.Push(MThread::InternalCommands::Stop, 10,
nullptr,
nullptr );
58 CmdPipe::Command cmd= cmdPipe.Pop();
61 if( cmd.cmd.IsEnumType<InternalCommands>() )
66 switch (cmd.cmd.Get<InternalCommands>())
68 case InternalCommands::Stop:
71 <<
"\" received stop command" )
72 if( stoppedFlag == false )
73 ALIB_ERROR("ATHR", NString256("MThread \"") << GetName()
74 << "\": Stop command in pipe, but stop flag not set")
80 case InternalCommands::NoCommand:
81 ALIB_ERROR(
"ATHR",
"Illegal command 'NoCommand' received.")
98 NString256 msg(
"MThread \""); msg << GetName() <<
"\" is stopping.";
99 if( cmdPipe.PeekSize() > 0 )
101 msg <<
' ' << cmdPipe.PeekSize() <<
"commands still in pipe!" <<
NewLine();
102 for(
int i= 0; i < std::min(10, cmdPipe.PeekSize()) ; ++i)
103 msg <<
" " << i <<
": " << cmdPipe.PeekCmd(i).cmd <<
NewLine();
112void MThread::CmdPipe::Push(Enum cmd,
int priority, Box data, Box data2)
116 std::list<Command>::iterator it= pipe.begin();
117 while(it != pipe.end())
119 if(priority <= (*it).priority)
125 it= pipe.insert(it, Command(cmd,priority,data, data2));
135MThread::CmdPipe::Command MThread::CmdPipe::Pop()
143 while(pipe.size()==0)
146 WaitForNotification();
149 if( pipe.size() == 0)
152 ALIB_WARNING("ATHR", NString256("Cmd pipe growing to: ") << pipe.size() )
157 Command msg(pipe.back());
166MThread::CmdPipe::Command MThread::CmdPipe::PeekCmd(
int n)
168 auto it= pipe.begin();
169 for(
int i= 0; i < n ; ++i)
172 return it != pipe.end() ? *it : Command( InternalCommands::NoCommand, 0,
nullptr,
nullptr );
#define ALIB_WARNING(...)
#define ALIB_MESSAGE(...)
#define ALIB_WARNINGS_RESTORE
#define ALIB_WARNINGS_ALLOW_SPARSE_ENUM_SWITCH
#define ALIB_CALLER_PRUNED
constexpr CString NewLine()
threads::Thread Thread
Type alias in namespace alib.
NLocalString< 256 > NString256
Type alias name for TLocalString<nchar,256> .