/**************************************************************************/
/*                                                                        */
/*                                 Sources                                */
/*                                from  the                               */
/*                           XSC SOFTWARE PACKAGE                         */
/*                                                                        */
/*                Copyright (c) 1997 University of Karlsruhe              */
/*                     Institute for Appl. Mathematics                    */
/*                                                                        */
/* This program is free software for non-commercial use. For details, see */
/* the file LICENSE.XSC, distributed with this software package.          */
/*                                                                        */
/* This program is distributed WITHOUT ANY WARRANTY. For details, see the */
/* file LICENSE.XSC, distributed with this software package.              */
/*                                                                        */
/**************************************************************************/

/* RCS $Id: a_time.c,v 1.5 1997/09/25 16:54:05 ae59 Exp $ */
/*
$Log: a_time.c,v $
 * Revision 1.5  1997/09/25  16:54:05  ae59
 * Copyright-message
 *
 * Revision 1.4  1995/08/22  11:54:11  ae59
 * support of IBM_EMX similar to getrusage (timeval)
 *
 * Revision 1.3  1995/01/20  15:20:31  ae59
 * linux supports getrusage
 *
 * Revision 1.2  1994/11/02  14:07:45  ae59
 * use getrusage for timer for Dec_alpha osf/1
 *
 * Revision 1.1  1994/01/27  13:20:51  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : a_time.c                              */
/*                                                              */
/*      Entries         : a_intg a_gtim()                       */
/*                      : void   a_itim()                       */
/*                                                              */
/*      Description     : Gets System CPU Time from clock       */
/*                        in ms sec, may wrap around on some    */
/*                        systems. Init timer, get timer        */
/*                        recognizes SUN systems                */
/*                                                              */
/*      Function value  : time between a_itim and a_gtim call   */
/*                                                              */
/*      Date            : 1993-09-13                            */
/*      1993-09-13 : new routine                                */
/****************************************************************/

#ifndef ALL_IN_ONE
#ifdef AIX
#include "/u/p88c/runtime/o_defs.h"
#else
#include "o_defs.h"
#endif
#define local
#endif

a_intg a_tvar; /* this var holds initial timer value from a_itim */


#if SUN4_OS4_C+DEC_ALPHA_C+IBM_LINUX_C+IBM_EMX_C
/* timer for sun4 os4, OSF/1  systems */
/* holds rusage structure */
#include <sys/time.h>
#include <sys/resource.h>

#if IBM_EMX_C
/* emx 0.9a does not support getrusage and rusage   */
/* but struct timeval and timezone and gettimeofday */
struct rusage {
	struct timeval ru_utime;
};

int getrusage(who, ruse)
int who;
struct rusage * ruse;
{
	return gettimeofday(&(ruse->ru_utime),NULL);
}
#endif

#ifdef LINT_ARGS
local void   a_itim(void)
#else
local void   a_itim()
#endif
        {

        struct rusage buf;
	   int ret;

        E_TPUSH("a_itim")

        ret=getrusage(0,&buf); 
	   a_tvar = (a_intg)(buf.ru_utime.tv_sec*1000 + 
					 buf.ru_utime.tv_usec / 1000 ); 

        E_TPOPP("a_itim")
        return;
        }

#ifdef LINT_ARGS
local a_intg a_gtim(void)
#else
local a_intg a_gtim()
#endif
        {
        register a_intg res;
        struct rusage buf;

        E_TPUSH("a_gtim")

        res=getrusage(0,&buf); 
	   res = (a_intg)(buf.ru_utime.tv_sec*1000 - a_tvar + 
	                  buf.ru_utime.tv_usec / 1000 ); 

        E_TPOPP("a_gtim")
        return(res);
        }
 
#else
/* timer for non sun systems */
#ifdef LINT_ARGS
local void   a_itim(void)
#else
local void   a_itim()
#endif
        {

        E_TPUSH("a_itim")

        a_tvar = a_clck();

        E_TPOPP("a_itim")
        return;
        }

#ifdef LINT_ARGS
local a_intg a_gtim(void)
#else
local a_intg a_gtim()
#endif
        {
        register a_intg res;

        E_TPUSH("a_gtim")

        res = (a_clck()-a_tvar) / 1000;

        E_TPOPP("a_gtim")
        return(res);
        }
#endif




