The ChSnoozer class is an easy way of putting a thread to sleep for a specified amount of time, but allowing it to wake up early. This is great for safely exiting threads that loop around some processing and then sleep for a while.
The idea for this came to me while reading one of Jon Wätte's many posts to the Be Developer's mailing list.
#include "Ch/ChSnoozer.h" ChSnoozer( const char *name = "Snoozer" );
Create a new ChSnoozer object with a name of name.
bool IsValid( void );
Returns true if the ChSnoozer is valid, or false if it's not. Currently, you can get an invalid ChSnoozer by providing the constructor with a name of NULL or if the create_sem() call inside the constructor fails.
You should always check to be sure your newly created ChSnoozer is valid before attempting to use it.
bool SleepFor( const bigtime_t sleep_time );
Sleep for sleep_time seconds. SleepFor() will return true if the ChSnoozer managed to sleep for sleep_time seconds, or false if it woke up early.
status_t WakeUp( void );
Wake up a snoozing ChSnoozer. Return values are the same as for release_sem() in the Kernel Kit.
Please see the libCh Overview for licensing information.
Last modified: $Date: 1998/04/14 00:51:27 $