/* ******************************************************************************* * Copyright (c) 1996 Martin Poole * ******************************************************************************* ** ** WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! ** ** Any changes to be made to this file should first be checked with ** mplib1 source control for library integrity. ** ** mplib1 source control can be reached at mplib1@quatermass.co.uk ** * * * $Source: /home/cvs/cvsroot/onelan/onelan/src/mplib1/libsrc/stopwatch.c,v $ * $Author: mpoole $ * $Date: 2002/10/07 09:37:39 $ * $Revision: 1.2 $ * * ******************************************************************************* * * * $Log: stopwatch.c,v $ * Revision 1.2 2002/10/07 09:37:39 mpoole * Initial checkin of mplib1-3.1.0 * * Revision 1.1 2002/10/07 09:36:57 mpoole * Initial checkin of mplib1-3.1.0 * * ******************************************************************************* */ #ident "$Header: /home/cvs/cvsroot/onelan/onelan/src/mplib1/libsrc/stopwatch.c,v 1.2 2002/10/07 09:37:39 mpoole Exp $" /* ------------------------------------------------------------------ Include files ------------------------------------------------------------------ */ #include #include #include #include #include #include #include #include #include /* ------------------------------------------------------------------ defines ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ Code starts here ------------------------------------------------------------------ */ static int get_time( struct timeval *tvp ) { int rv; #ifdef H_GETTIMEOFDAY_2_NULL rv = gettimeofday( tvp, NULL ); #else #ifdef H_GETTIMEOFDAY_2_PARAMS struct timezone my_tz; my_tz.tz_minuteswest = 0; my_tz.tz_dsttime = 0; rv = gettimeofday( tvp, &my_tz ); #else rv = gettimeofday( tvp ); #endif #endif return(rv); } int init_stopwatch( struct stopwatch *stp ) { if (stp) memset( stp, '\0', STOPWATCH_SIZE ); return(0); } int start_stopwatch( struct stopwatch *stp ) { int rv; if (stp) { rv = get_time( &stp->start_time ); }else { rv= -1; errno = ENOENT; } return(rv); } int stop_stopwatch( struct stopwatch *stp ) { int rv; struct timeval end_time; if (stp && stp->start_time.tv_sec) { rv = get_time( &end_time ); accum_stop_timevals( stp, &end_time ); }else { rv= -1; errno = ENOENT; } return(rv); } int accrete_stopwatch( struct stopwatch *stp_into, struct stopwatch *stp_from ) { add_timevals( &stp_into->cumulative_time, &stp_from->cumulative_time ); return(0); } /* -- End of File -- */