Files CCore/inc/task/Event.h CCore/src/task/Event.cpp
Event is similar to the Sem. But instead of counter it has a boolean flag as an internal logical state. The method trigger() sets this flag. And the method wait() clears it if it is set. But if the flag is cleared, the method is waiting until it can be performed.
The event "basket" can store only one apple.
class Event : public Funchor_nocopy
{
....
public:
// constructors
explicit Event(bool flag=false);
explicit Event(TextLabel name,bool flag=false);
~Event();
// trigger
bool trigger();
// wait
bool try_wait();
void wait();
bool wait(MSec timeout);
bool wait(TimeScope time_scope);
// functions
void trigger_void() { trigger(); }
Function<void (void)> function_trigger() { return FunctionOf(this,&Event::trigger_void); }
};
The constructor argument flag is the initial event state. It is false by default.
trigger() sets the flag. If the flag is already set, the return value is false, otherwise it is true.
try_wait() tries to consume the event. This method never blocks. If the event is not triggered, the return value is false.
wait() waits until the event can be consumed and consume it.
wait(MSec) and wait(TimeScope) are timed variants of the wait(). These methods wait up to the specified timeout is expired, then operation failed. The return value is true, if the method was successful.
HCore Event has the common interface.
class Event : public Funchor_nocopy
{
....
public:
// constructors
explicit Event(bool flag=false);
explicit Event(TextLabel name,bool flag=false);
~Event();
// trigger
bool trigger();
// wait
bool try_wait();
void wait();
bool wait(MSec timeout);
bool wait(TimeScope time_scope);
// functions
void trigger_void() { trigger(); }
Function<void (void)> function_trigger() { return FunctionOf(this,&Event::trigger_void); }
};
XCore Event is essentially the same, but has trigger() method variants for different execution contexts.
class Event : public Funchor_nocopy
{
....
public:
// constructors
explicit Event(bool flag=false);
explicit Event(TextLabel name,bool flag=false);
~Event();
TextLabel getName() const { return name; }
// trigger
bool trigger();
bool trigger_int();
bool trigger_any();
// wait
bool try_wait();
void wait();
bool wait(MSec timeout);
bool wait(TimeScope time_scope);
// functions
void trigger_void() { trigger(); }
void trigger_int_void() { trigger_int(); }
void trigger_any_void() { trigger_any(); }
Function<void (void)> function_trigger() { return FunctionOf(this,&Event::trigger_void); }
Function<void (void)> function_trigger_int() { return FunctionOf(this,&Event::trigger_int_void); }
Function<void (void)> function_trigger_any() { return FunctionOf(this,&Event::trigger_any_void); }
};