2001-09-09 22:24:39 -04:00
|
|
|
/* timing.c
|
2014-12-05 04:31:08 -05:00
|
|
|
* - Timing functions
|
|
|
|
*
|
2018-10-12 06:28:09 -04:00
|
|
|
* Copyright (C) 2014 Michael Smith <msmith@icecast.org>,
|
|
|
|
* Brendan Cully <brendan@xiph.org>,
|
|
|
|
* Karl Heyes <karl@xiph.org>,
|
|
|
|
* Jack Moffitt <jack@icecast.org>,
|
|
|
|
* Ed "oddsock" Zaleski <oddsock@xiph.org>,
|
|
|
|
* Ralph Giles <giles@xiph.org>,
|
|
|
|
* Copyright (C) 2012-2018 Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>
|
2014-12-05 04:31:08 -05:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
2001-09-09 22:24:39 -04:00
|
|
|
|
2003-03-08 11:05:38 -05:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2001-09-09 22:24:39 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2002-02-06 20:04:09 -05:00
|
|
|
#include <windows.h>
|
|
|
|
#include <mmsystem.h>
|
|
|
|
#else
|
2009-07-07 12:37:31 -04:00
|
|
|
#ifdef TIME_WITH_SYS_TIME
|
|
|
|
# include <sys/time.h>
|
|
|
|
# include <time.h>
|
|
|
|
#else
|
|
|
|
# ifdef HAVE_SYS_TIME_H
|
|
|
|
# include <sys/time.h>
|
|
|
|
# else
|
|
|
|
# include <time.h>
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2002-02-06 20:04:09 -05:00
|
|
|
#include <unistd.h>
|
2001-09-09 22:24:39 -04:00
|
|
|
#endif
|
|
|
|
|
2003-06-05 15:18:00 -04:00
|
|
|
#ifdef HAVE_SYS_SELECT_H
|
|
|
|
#include <sys/select.h>
|
2003-06-05 15:02:36 -04:00
|
|
|
#endif
|
|
|
|
|
2009-01-07 21:18:11 -05:00
|
|
|
#ifdef HAVE_SYS_TIMEB_H
|
2003-10-19 23:08:46 -04:00
|
|
|
#include <sys/timeb.h>
|
|
|
|
#endif
|
|
|
|
|
2018-11-02 07:20:04 -04:00
|
|
|
#include <igloo/timing.h>
|
2001-09-09 22:24:39 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns milliseconds no matter what.
|
|
|
|
*/
|
2018-10-12 06:55:24 -04:00
|
|
|
uint64_t igloo_timing_get_time(void)
|
2001-09-09 22:24:39 -04:00
|
|
|
{
|
2009-01-07 21:18:11 -05:00
|
|
|
#ifdef HAVE_GETTIMEOFDAY
|
2003-03-14 21:10:19 -05:00
|
|
|
struct timeval mtv;
|
2001-09-09 22:24:39 -04:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
gettimeofday(&mtv, NULL);
|
2001-09-09 22:24:39 -04:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
return (uint64_t)(mtv.tv_sec) * 1000 + (uint64_t)(mtv.tv_usec) / 1000;
|
2009-01-07 21:18:11 -05:00
|
|
|
#elif HAVE_FTIME
|
2009-07-07 12:37:31 -04:00
|
|
|
struct timeb t;
|
2009-01-07 21:18:11 -05:00
|
|
|
|
2009-07-07 12:37:31 -04:00
|
|
|
ftime(&t);
|
|
|
|
return t.time * 1000 + t.millitm;
|
2009-01-07 21:18:11 -05:00
|
|
|
#else
|
|
|
|
#error need time query handler
|
2001-09-09 22:24:39 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-07-07 12:37:31 -04:00
|
|
|
|
2018-10-12 06:55:24 -04:00
|
|
|
void igloo_timing_sleep(uint64_t sleeptime)
|
2001-09-09 22:24:39 -04:00
|
|
|
{
|
2003-03-14 21:10:19 -05:00
|
|
|
struct timeval sleeper;
|
2001-09-09 22:24:39 -04:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
sleeper.tv_sec = sleeptime / 1000;
|
|
|
|
sleeper.tv_usec = (sleeptime % 1000) * 1000;
|
2001-09-09 22:24:39 -04:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
/* NOTE:
|
|
|
|
* This should be 0 for the first argument. The linux manpage
|
|
|
|
* says so. The solaris manpage also says this is a legal
|
|
|
|
* value. If you think differerntly, please provide references.
|
|
|
|
*/
|
2004-01-29 19:08:02 -05:00
|
|
|
#ifdef WIN32
|
|
|
|
Sleep(sleeptime);
|
|
|
|
#else
|
|
|
|
select(1, NULL, NULL, NULL, &sleeper);
|
|
|
|
#endif
|
2001-09-09 22:24:39 -04:00
|
|
|
}
|