Main Page Class Hierarchy Compound List File List Compound Members File Members

# wait_timer.c

Go to the documentation of this file.

    00001
    00002 /*
    00003  *   THIS FILE IS UNDER RCS - DO NOT MODIFY UNLESS YOU HAVE
    00004  *   CHECKED IT OUT USING THE COMMAND CHECKOUT.
    00005  *
    00006  *    $Id: wait__timer_8c-source.html,v 1.1 2006/05/19 16:55:02 paulf Exp $
    00007  *
    00008  *    Revision history:
    00009  *     $Log: wait__timer_8c-source.html,v $
    00009  *     Revision 1.1  2006/05/19 16:55:02  paulf
    00009  *     first inclusion
    00009  *
    00010  *     Revision 1.1  2000/02/14 18:53:30  lucky
    00011  *     Initial revision
    00012  *
    00013  *
    00014  */
    00015
    00016      /********************************************************************
    00017       *                wait_timer.c   for   Windows NT                   *
    00018       *                                                                  *
    00019       ********************************************************************/
    00020
    00021 #include <earthworm.h>
    00022
    00023
    00024          /**********************************************************
    00025           *                    init_wait_timer()                   *
    00026           *                Create a new timer object               *
    00027           *                                                        *
    00028           *  Returns -1 if an error is detected. errorCode is set. *
    00029           **********************************************************/
    00030
    00031 int init_wait_timer( timer_t *timerHandle, DWORD *errorCode )
    00032 {
    00033    LPSECURITY_ATTRIBUTES securityAttributes = NULL;  // Default security attributes
    00034    BOOL                  manualReset = FALSE;        // This is a synchronization timer
    00035    LPCTSTR               timerName = NULL;           // The timer is unnamed
    00036
    00037    *timerHandle = CreateWaitableTimer( securityAttributes, manualReset, timerName );
    00038    if ( timerHandle == NULL )
    00039    {
    00040       *errorCode = GetLastError();
    00041       return -1;
    00042    }
    00043    return 0;
    00044 }
    00045
    00046
    00047           /***********************************************************
    00048            *                    start_wait_timer()                   *
    00049            *  Start the timer.                                       *
    00050            *  lPeriod is the repeat interval in milliseconds.        *
    00051            *                                                         *
    00052            *  Returns -1 if an error is detected. errorCode is set.  *
    00053            ***********************************************************/
    00054
    00055 int start_wait_timer( timer_t timerHandle, LONG lPeriod, DWORD *errorCode )
    00056 {
    00057    LARGE_INTEGER     dueTime;                   // 100 nanosecond intervals
    00058    PTIMERAPCROUTINE  fnComplRoutine = NULL;     // No completion routine
    00059    LPVOID            argToComplRoutine = NULL;  // No data passed to completion routine
    00060    BOOL              fResume = FALSE;           // No power conservation mode
    00061    BOOL              returnValue;
    00062
    00063    dueTime.QuadPart = (LONGLONG)-1;             // Start immediately
    00064
    00065    returnValue = SetWaitableTimer( timerHandle, &dueTime, lPeriod,
    00066                                    fnComplRoutine, argToComplRoutine, fResume );
    00067    if ( returnValue == 0 )
    00068    {
    00069       *errorCode = GetLastError();
    00070       return -1;
    00071    }
    00072    return 0;
    00073 }
    00074
    00075
    00076          /**********************************************************
    00077           *                      wait_timer()                      *
    00078           *             Wait for the timer to complete             *
    00079           *                                                        *
    00080           *  Returns -1 if an error is detected. errorCode is set. *
    00081           *  Returns -2 if the wait timed out                      *
    00082           **********************************************************/
    00083
    00084 int wait_timer( timer_t timerHandle, DWORD *errorCode )
    00085 {
    00086    DWORD milliseconds = 5000;         // Time out in five seconds
    00087    DWORD returnValue;
    00088
    00089    returnValue = WaitForSingleObject( timerHandle, milliseconds );
    00090
    00091    if ( returnValue == WAIT_FAILED )
    00092    {
    00093       *errorCode = GetLastError();
    00094       return -1;
    00095    }
    00096
    00097    if ( returnValue == WAIT_TIMEOUT )
    00098       return -2;
    00099
    00100    return 0;
    00101 }