root/trunk/libffado/src/libutil/SystemTimeSource.cpp

Revision 863, 2.1 kB (checked in by ppalmers, 15 years ago)

fix cycle timer DLL code

Line 
1 /*
2  * Copyright (C) 2005-2007 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include "SystemTimeSource.h"
25 #include "Time.h"
26
27 // needed for clock_nanosleep
28 #ifndef _GNU_SOURCE
29     #define _GNU_SOURCE
30 #endif
31
32 #include <time.h>
33
34 namespace Util {
35
36 IMPL_DEBUG_MODULE( SystemTimeSource, SystemTimeSource, DEBUG_LEVEL_NORMAL );
37
38 SystemTimeSource::SystemTimeSource() {
39 }
40
41 SystemTimeSource::~SystemTimeSource() {
42 }
43
44 void
45 SystemTimeSource::SleepUsecRelative(ffado_microsecs_t usecs) {
46     //usleep(usecs);
47     struct timespec ts;
48     ts.tv_sec = usecs / (1000000LL);
49     ts.tv_nsec = (usecs % (1000000LL)) * 1000LL;
50     clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL);
51 }
52
53 void
54 SystemTimeSource::SleepUsecAbsolute(ffado_microsecs_t wake_at_usec) {
55     struct timespec ts;
56     ts.tv_sec = wake_at_usec / (1000000LL);
57     ts.tv_nsec = (wake_at_usec % (1000000LL)) * 1000LL;
58     clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, NULL);
59 }
60
61 ffado_microsecs_t SystemTimeSource::getCurrentTime() {
62 //     struct timeval tv;
63 //     gettimeofday(&tv, NULL);
64 //     return tv.tv_sec * 1000000ULL + tv.tv_usec;
65     struct timespec ts;
66     clock_gettime(CLOCK_REALTIME, &ts);
67     return (ffado_microsecs_t)(ts.tv_sec * 1000000LL + ts.tv_nsec / 1000LL);
68 }
69
70 ffado_microsecs_t SystemTimeSource::getCurrentTimeAsUsecs() {
71     return getCurrentTime();
72 }
73
74 } // end of namespace Util
Note: See TracBrowser for help on using the browser.