Download Source Code

CTlSignal Class Reference

Encapsulates two events for syncronizing threads. More...

#include <ThreadSafe.h>

List of all members.

Public Member Functions

 CTlSignal ()
 Default constructor.
virtual ~CTlSignal ()
 Destructor.
HANDLE GetStartEvent ()
 Returns the handle to the start event.
HANDLE GetDoneEvent ()
 Returns the handle to the done event.
BOOL SignalStart ()
 Sets the start event signal.
BOOL SignalDone ()
 Sets the done event signal.
BOOL ResetStart ()
 Resets the start event signal.
BOOL ResetDone ()
 Resets the done event signal.
BOOL WaitStart (DWORD dwTimeout)
 Waits for the start event.
BOOL WaitDone (DWORD dwTimeout)
 Waits for the done event.
DWORD WaitStart (DWORD dwTimeout, HANDLE hOtherEvent)
 Waits for the start event.
DWORD WaitDone (DWORD dwTimeout, HANDLE hOtherEvent)
 Waits for the done event.


Detailed Description

Encapsulates two events for syncronizing threads.

Typical use

Worker thread...

    // Ready for work
    g_cSignal.SignalDone();

    // Worker thread loop
    while ( g_cSignal.WaitStart( INFINITE ) )
    {
        // Acknowledge start
        g_cSignal.ResetStart();

        // Want exit?
        if ( g_bExit ) break;

        // Do the work
        DoWork();

        // Signal that we're done
        g_cSignal.SignalDone();

    } // end while

User Thread...

    // Is thread done with the last task?
    if ( g_cSignal.WaitDone( 0 ) )
    {
        // Acknowledge done
        g_cSignal.ResetDone();

        CreateWork();

        // Start the worker thread
        g_cSignal.SignalStart();

    } // end if

    // Go do something else


Member Function Documentation

DWORD CTlSignal::WaitDone DWORD  dwTimeout,
HANDLE  hOtherEvent
[inline]
 

Waits for the done event.

Parameters:
[in] dwTimeout - Maximum amount of time to wait
[in] hOtherEvent - Handle to another event to wait for
Returns:
1 if done event was set, 2 if hOtherEvent was set, otherwise zero.
See also:

BOOL CTlSignal::WaitDone DWORD  dwTimeout  )  [inline]
 

Waits for the done event.

Parameters:
[in] dwTimeout - Maximum amount of time to wait
Returns:
Non-zero if done event was set
See also:

DWORD CTlSignal::WaitStart DWORD  dwTimeout,
HANDLE  hOtherEvent
[inline]
 

Waits for the start event.

Parameters:
[in] dwTimeout - Maximum amount of time to wait
[in] hOtherEvent - Handle to another event to wait for
Returns:
1 if start event was set, 2 if hOtherEvent was set, otherwise zero.
See also:

BOOL CTlSignal::WaitStart DWORD  dwTimeout  )  [inline]
 

Waits for the start event.

Parameters:
[in] dwTimeout - Maximum amount of time to wait
Returns:
Non-zero if start event was set
See also:


The documentation for this class was generated from the following file:
  • inc/ThreadSafe.h
Copyright Robert Umbehant
This documentation is covered by the LGPL