Public Member Functions

kNet::Event Class Reference

Event is an inter-thread synchronization primitive that can be in one of two states: Set or Cleared. More...

#include <Event.h>

List of all members.

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.

Detailed Description

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.


Member Function Documentation

void kNet::Event::Create ( EventWaitType  type  ) 

Initializes the event to a new instance.

If the Event was previously initialized, does *not* Close the old instance.

Todo:
Remove these, just a bit of immediate-mode testing here.
Todo:
Return success or failure.

References LOG, Reset(), Set(), and Test().

Referenced by kNet::CreateNewEvent().

bool kNet::Event::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.

Returns true if the event was set during this time, or false if timout occurred.

References IsNull(), and LOG.

Referenced by Test().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines