Event is an inter-thread synchronization primitive that can be in one of two states: Set or Cleared. More...
#include <Event.h>
Public Member Functions | |
| Event () | |
| Creates a null event. Call Event::Create to initialize the event. | |
| void | Create (EventWaitType type) |
| Initializes the event to a new instance. | |
| void | Close () |
| Deinitializes the Event. If there exists any copies of this Event, their state will be undefined. | |
| bool | IsNull () const |
| Returns true if this event is uninitialized. | |
| bool | IsValid () const |
| Returns true if this event is not null. | |
| void | Reset () |
| Clears the event, i.e. sets it to "0". | |
| void | Set () |
| Sets the event, i.e. sets it to "1". | |
| bool | Test () const |
| Returns true if the event is in set state. | |
| bool | Wait (unsigned long msecs) const |
| Returns true if the event was set, or got set during the timeout period, or returns false if the event was not set before the timeout occurred. | |
| EventWaitType | Type () const |
| Returns the underlying type of the event, specifying what kind of system object is being represented by this event. | |
Event is an inter-thread synchronization primitive that can be in one of two states: Set or Cleared.
A thread can avoid busy-waiting on a condition by using an Event to represent the triggering of that condition and calling its Wait() function to observe when the condition occurs.
Network socket read and write availability can be represented as an Event as well. The kNet::EventArray EventArray class can be used to wait on list of events. This allows a mixture of socket and application events to be handled using a single select() call.
To create a new event, call kNet::CreateNewEvent CreateNewEvent with the wait type of EventWaitSignal.
The Event class does not follow RAII or data sharing patterns to avoid thread-safety issues. Therefore it is important to note that:
This class represents a WSAEVENT on Windows, and socket or an eventfd on unix.
| void kNet::Event::Create | ( | EventWaitType | type | ) |
| bool kNet::Event::Wait | ( | unsigned long | msecs | ) | const |
1.7.1