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 runtime-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 |
|
---|