#include <Threading.h>

extern int	ShutdownControl;
extern int	ThreadCount;
extern int	EnforcedWait;

void *Keeper( void )
{
/* 
   This just does reocurring jobs,
   an example on how to add a thread that does something.
   Right now its set to wait for the 'q' key pressed on
   the stdin, then call an exit.
*/
int c;
/* Up the thread running cout ... */
pthread_mutex_lock(&threadcount_mutex);
ThreadCount++;
pthread_mutex_unlock(&threadcount_mutex);

/* Report that I'm alive :) */
Error(0,"Keeper Thread Running");

while ( 1 )
{
c = getc(stdin);
if ( toupper(c) == 'Q' )
   {
   Error(4,"User requested shutdown");
   }

/* Shutdown time has been declared */
if ( ShutdownControl == 1 )
   {
   Error(3,"Keeper here, I'm closing, bye");
   /* Boom biddy bye bye ... now it's time to die */
   pthread_mutex_lock(&threadcount_mutex);
   ThreadCount--;
   pthread_mutex_unlock(&threadcount_mutex);
   pthread_exit( NULL );
   }
usleep(EnforcedWait);
/* Sleep so thread isn't doing constant ifs */
}
}
