/** * Convenience methods which interact with the system clock in microseconds * UTC. * * Author: adambuckley@gmx.net * Version: $Id: utc.c,v 1.2 2002/05/23 12:13:55 adam Exp $ */ /** * This source code is copyright (c) 2002 Adam Buckley, . * * This source code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This source code is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * The GNU General Public License can be found at * http://www.gnu.org/licenses/gpl.html */ #ifndef ADAMLIB_UTC_C #define ADAMLIB_UTC_C #include #include /** * Returns the number of microseconds elapsed since 00:00:00 UTC, * January 1, 1970. */ long long getUtc() { struct timeval tv; gettimeofday(&tv, 0); return (long long) tv.tv_sec * 1000000 + tv.tv_usec; } /** * Blocks execution until absolute time 'waitUntilTime', which is specified in * microseconds UTC. */ void waitUntil(long long waitUntilTime) { int timeToWait = waitUntilTime - getUtc(); if(timeToWait > 0) usleep(timeToWait); } #endif