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

Revision 2171, 2.0 kB (checked in by jwoithe, 12 years ago)

A second pass at addressing ticket #242. Define a global clock source within the SystemTimeSource? object and use this whenever clock_gettime() is called. On systems which support the new raw1394_read_cycle_timer_and_clock() libraw1394 call and CLOCK_MONOTONIC_RAW, these changes should ensure that all timing-sensitive parts of FFADO are using the same clock source. System tests under tests/systemtests/ have not been converted to use this new framework because they exist for different purposes and are not using the FFADO streaming infrastructure.

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  * Copyright (C) 2012 by Jonathan Woithe
4  *
5  * This file is part of FFADO
6  * FFADO = Free Firewire (pro-)audio drivers for linux
7  *
8  * FFADO is based upon FreeBoB.
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 2 of the License, or
13  * (at your option) version 3 of the License.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 #ifndef __FFADO_SYSTEMTIMESOURCE__
26 #define __FFADO_SYSTEMTIMESOURCE__
27
28 #include "../debugmodule/debugmodule.h"
29
30 #include <stdint.h>
31
32 typedef uint64_t ffado_microsecs_t;
33
34 // Ensure this is defined even for kernels/glib versions which don't include
35 // it.  This allows compile-time testing for the feature.
36 #ifndef CLOCK_MONOTONIC_RAW
37 #define CLOCK_MONOTONIC_RAW 4
38 #endif
39
40 namespace Util {
41
42 class SystemTimeSource
43 {
44 private: // don't allow objects to be created
45     SystemTimeSource() {};
46     virtual ~SystemTimeSource() {};
47
48 public:
49     static bool setSource(clockid_t id);
50     static clockid_t getSource(void);
51     static int clockGettime(struct timespec *tp);
52
53     static ffado_microsecs_t getCurrentTime();
54     static ffado_microsecs_t getCurrentTimeAsUsecs();
55
56     static void SleepUsecRelative(ffado_microsecs_t usecs);
57     static void SleepUsecAbsolute(ffado_microsecs_t wake_time);
58    
59     /**
60      * @brief sleeps for a random amount of usecs
61      * @param max_usec max usecs
62      * @return number of usecs slept
63      */
64     static ffado_microsecs_t SleepUsecRandom(ffado_microsecs_t max_usec);
65 };
66
67 } // end of namespace Util
68
69 #endif /* __FFADO_SYSTEMTIMESOURCE__ */
70
71
Note: See TracBrowser for help on using the browser.