7 #include <MelLibType.h>
9 #include <tasking/Process.h>
10 #include <core/Callback.h>
11 #include <tasking/ProcessScheduler.h>
17 using ::mel::tasking::Process;
20 enum class EEventMTWaitCode {
24 static const int EVENTMT_WAIT_INFINITE = -1;
28 EventBase(
bool autoRelease=
true,
bool signaled=
false);
33 typedef list< std::shared_ptr<Process> > TProcessList;
34 void _triggerActivation(
bool sendToAll );
38 TProcessList mWaitingProcesses;
39 void _set(
bool sendToAll );
50 void set(
bool sendToAll)
52 std::scoped_lock<std::mutex> lck(mCS);
53 EventBase::_set(sendToAll);
56 EEventMTWaitCode _wait(
unsigned int msecs );
58 EEventMTWaitCode _waitAndDo( F postSleep,
unsigned int msecs )
60 EEventMTWaitCode result = EEventMTWaitCode::EVENTMT_WAIT_OK;
65 mWaitingProcesses.push_back( p );
68 if ( msecs == EVENTMT_WAIT_INFINITE )
80 switch ( switchResult )
83 result = EEventMTWaitCode::EVENTMT_WAIT_KILL;
86 result = EEventMTWaitCode::EVENTMT_WAIT_OK;
89 result = EEventMTWaitCode::EVENTMT_WAIT_TIMEOUT;
95 mWaitingProcesses.remove( p );
114 inline void set(
bool sendToAll)
116 EventBase::_set(sendToAll);
119 EEventMTWaitCode _wait(
unsigned int msecs );
121 EEventMTWaitCode _waitAndDo( F postSleep,
unsigned int msecs )
123 EEventMTWaitCode result = EEventMTWaitCode::EVENTMT_WAIT_OK;
127 mWaitingProcesses.push_back( p );
130 if ( msecs == EVENTMT_WAIT_INFINITE )
140 switch ( switchResult )
143 result = EEventMTWaitCode::EVENTMT_WAIT_KILL;
146 result = EEventMTWaitCode::EVENTMT_WAIT_OK;
149 result = EEventMTWaitCode::EVENTMT_WAIT_TIMEOUT;
154 mWaitingProcesses.remove( p );
166 template <
class MultithreadPolicy = EventMTThreadSafePolicy>
class Event_mthread :
public MultithreadPolicy
177 Event_mthread(
bool autoRelease=
true,
bool signaled=
false):MultithreadPolicy(autoRelease,signaled){}
184 void set(
bool sendToAll =
true ){MultithreadPolicy::set(sendToAll);}
191 inline EEventMTWaitCode
wait(
unsigned int msecs = EVENTMT_WAIT_INFINITE)
193 return MultithreadPolicy::_wait( msecs );
201 EEventMTWaitCode
waitAndDo( F postSleep,
unsigned int msecs = EVENTMT_WAIT_INFINITE )
203 return MultithreadPolicy::_waitAndDo( postSleep,msecs );
create Callback from callable
Definition: Callback_Impl.h:142
class similar to Event Class (which is for thread synchronization) but for Process (with Microthread ...
Definition: Event_mthread.h:167
EEventMTWaitCode wait(unsigned int msecs=EVENTMT_WAIT_INFINITE)
Definition: Event_mthread.h:191
void set(bool sendToAll=true)
Definition: Event_mthread.h:184
Event_mthread(bool autoRelease=true, bool signaled=false)
Definition: Event_mthread.h:177
EEventMTWaitCode waitAndDo(F postSleep, unsigned int msecs=EVENTMT_WAIT_INFINITE)
Definition: Event_mthread.h:201
Definition: Event_mthread.h:26
Policy for multithread safe event.
Definition: Event_mthread.h:47
Policy for non-multithread safe event.
Definition: Event_mthread.h:111
static ESwitchResult sleepAndDo(F postSleep)
Sleep current process and execute given callable. To reactivate to you must use wakeUp.
Definition: Process.h:391
static ESwitchResult waitAndDo(unsigned int msegs, F postWait) OPTIMIZE_FLAGS
Wait for a given time and execute given callable.
Definition: Process.h:380
ESwitchResult
Reason why the process returns from context switch.
Definition: Process.h:127
@ ESWITCH_KILL
return from context switch because a kill
static std::shared_ptr< Process > getCurrentProcess()
Definition: Callback_Impl.h:11