eqemu

annotate src/timer.cc @ 12:2656099aff12

added copyright notices and license
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 18 Jul 2014 07:04:21 +0300
parents e9ab4861536d
children
rev   line source
nuclear@12 1 /*
nuclear@12 2 eqemu - electronic queue system emulator
nuclear@12 3 Copyright (C) 2014 John Tsiombikas <nuclear@member.fsf.org>,
nuclear@12 4 Eleni-Maria Stea <eleni@mutantstargoat.com>
nuclear@12 5
nuclear@12 6 This program is free software: you can redistribute it and/or modify
nuclear@12 7 it under the terms of the GNU General Public License as published by
nuclear@12 8 the Free Software Foundation, either version 3 of the License, or
nuclear@12 9 (at your option) any later version.
nuclear@12 10
nuclear@12 11 This program is distributed in the hope that it will be useful,
nuclear@12 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
nuclear@12 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
nuclear@12 14 GNU General Public License for more details.
nuclear@12 15
nuclear@12 16 You should have received a copy of the GNU General Public License
nuclear@12 17 along with this program. If not, see <http://www.gnu.org/licenses/>.
nuclear@12 18 */
nuclear@2 19 #include <unistd.h>
nuclear@2 20 #include <sys/time.h>
nuclear@2 21
nuclear@2 22 unsigned long get_msec()
nuclear@2 23 {
nuclear@2 24 static struct timeval tv0;
nuclear@2 25 struct timeval tv;
nuclear@2 26
nuclear@2 27 gettimeofday(&tv, 0);
nuclear@2 28 if(tv0.tv_sec == 0 && tv0.tv_usec == 0) {
nuclear@2 29 tv0 = tv;
nuclear@2 30 return 0;
nuclear@2 31 }
nuclear@2 32 return (tv.tv_sec - tv0.tv_sec) * 1000 + (tv.tv_usec - tv0.tv_usec) / 1000;
nuclear@2 33 }
nuclear@7 34
nuclear@7 35 void wait_for(unsigned long msec)
nuclear@7 36 {
nuclear@7 37 usleep(msec * 1000);
nuclear@7 38 }