/*************************************************************************** * DBS: Distributed Benchmark System * Copyright (c) 1995, 1996, 1997 Yukio Murayama * Copyright (c) 1995, 1996, 1997 Nara Institute of Science and Technology * All rights reserved. * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided only with the following * conditions are satisfied: * * 1. Both the copyright notice and this permission notice appear in * all copies of the software, derivative works or modified versions, * and any portions thereof, and that both notices appear in * supporting documentation. * 2. All advertising materials mentioning features or use of this * software must display the following acknowledgement: * This product includes software developed by Nara Institute of * Science and Technology and its contributors. * 3. Neither the name of Nara Institute of Science and Technology nor * the names of its contributors may be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND NARA * INSTITUTE OF SCIENCE AND TECHNOLOGY DISCLAIMS ANY LIABILITY OF * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF * THIS SOFTWARE. ALSO, THERE IS NO WARRANTY IMPLIED OR OTHERWISE, * NOR IS SUPPORT PROVIDED. * * Feedback of the results generated from any improvements or * extensions made to this software would be much appreciated. * Any such feedback should be sent to: * * Yukio Murayama * E-mail: * URL: * Address: Graduate School of Information Science, * Nara Institute of Science and Technology, * Takayama 8916-5, Ikoma, Nara, Japan * * Nara Institute of Science and Technology has the rights to * redistribute these changes. ***************************************************************************/ /***************************************************************** * Distributed Benchmark System * DBS Common routines * $Revision: 1.8 $ * $Date: 1997/02/11 03:14:10 $ * $Author: yukio-m $ *****************************************************************/ #include #include #include #include "dbs.h" /* * timeval to double * * tp -> double */ double timeval2double(tp) struct timeval *tp; { return (double)tp->tv_sec + (double)tp->tv_usec/1000000.0; } /* * Timeval Put * * double -> timeval */ void timeval_put(tp, a) struct timeval *tp; double a; { tp->tv_sec = (int)a; tp->tv_usec = (int)(a*1000000) % 1000000; } /* * Timeval Copy * * timeval2 -> timeval1 */ void timeval_cp(tp1, tp2) struct timeval *tp1, *tp2; { tp1->tv_sec = tp2->tv_sec; tp1->tv_usec = tp2->tv_usec; } /* * Timeval ADD * * timeval1 + timeval2 -> timeval1 */ void timeval_add(tp1, tp2) struct timeval *tp1, *tp2; { tp1->tv_sec += tp2->tv_sec; tp1->tv_usec += tp2->tv_usec; if (tp1->tv_usec >= 1000000) { tp1->tv_sec += tp1->tv_usec / 1000000; tp1->tv_usec %= 1000000; } } /* * Timeval SUB * * timeval1 - timeval2 -> timeval1 */ void timeval_sub(tp1, tp2) struct timeval *tp1, *tp2; { tp1->tv_sec -= tp2->tv_sec; tp1->tv_usec -= tp2->tv_usec; if (tp1->tv_usec < 0) { tp1->tv_sec --; tp1->tv_usec += 1000000; } } /* * Timeval SUB * * timeval + double -> timeval */ void timeval_add_double(tp, time) struct timeval *tp; double time; { tp->tv_sec = tp->tv_sec + (int)time; tp->tv_usec = tp->tv_usec + (int)(time*1000000) % 1000000; if (tp->tv_usec >= 1000000) { tp->tv_sec += tp->tv_usec / 1000000; tp->tv_usec %= 1000000; } }