~artfwo/ubuntu/raring/libffado/ftbfs-1110187

« back to all changes in this revision

Viewing changes to .pc/downgrade_to_r2166.patch/src/libutil/SystemTimeSource.cpp

  • Committer: Package Import Robot
  • Author(s): Adrian Knoth
  • Date: 2012-06-28 16:09:34 UTC
  • mfrom: (8.3.13 sid)
  • Revision ID: package-import@ubuntu.com-20120628160934-q9c9un43ptqu4v8m
Tags: 2.0.99+svn2171-2
* Add patch to downgrade the codebase to r2166 (Closes: #620427)
* Add fix for FTBFS on Big Endian machines

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2005-2008 by Pieter Palmers
 
3
 * Copytight (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
#include "SystemTimeSource.h"
 
26
#include "Time.h"
 
27
 
 
28
// needed for clock_nanosleep
 
29
#ifndef _GNU_SOURCE
 
30
    #define _GNU_SOURCE
 
31
#endif
 
32
 
 
33
#include <time.h>
 
34
#include <stdlib.h>
 
35
 
 
36
DECLARE_GLOBAL_DEBUG_MODULE;
 
37
 
 
38
namespace Util {
 
39
 
 
40
static clockid_t clock_id = CLOCK_REALTIME;
 
41
 
 
42
bool
 
43
SystemTimeSource::setSource(clockid_t id)
 
44
{
 
45
    struct timespec tp;
 
46
    // Determine at runtime whether the kernel has support for the
 
47
    // requested clock source.
 
48
    if (clock_gettime(id, &tp) == 0) {
 
49
        clock_id = id;
 
50
        return true;
 
51
    }
 
52
    return false;
 
53
}
 
54
 
 
55
clockid_t
 
56
SystemTimeSource::getSource(void)
 
57
{
 
58
    return clock_id;
 
59
}
 
60
 
 
61
int
 
62
SystemTimeSource::clockGettime(struct timespec *tp)
 
63
{
 
64
    return clock_gettime(clock_id, tp);
 
65
}
 
66
 
 
67
void
 
68
SystemTimeSource::SleepUsecRelative(ffado_microsecs_t usecs)
 
69
{
 
70
    //usleep(usecs);
 
71
    struct timespec ts;
 
72
    ts.tv_sec = usecs / (1000000LL);
 
73
    ts.tv_nsec = (usecs % (1000000LL)) * 1000LL;
 
74
    clock_nanosleep(clock_id, 0, &ts, NULL);
 
75
}
 
76
 
 
77
void
 
78
SystemTimeSource::SleepUsecAbsolute(ffado_microsecs_t wake_at_usec)
 
79
{
 
80
#if USE_ABSOLUTE_NANOSLEEP
 
81
    struct timespec ts;
 
82
    ts.tv_sec = wake_at_usec / (1000000LL);
 
83
    ts.tv_nsec = (wake_at_usec % (1000000LL)) * 1000LL;
 
84
    debugOutputExtreme(DEBUG_LEVEL_VERBOSE,
 
85
                       "clock_nanosleep until %"PRId64" sec, %"PRId64" nanosec\n",
 
86
                       (int64_t)ts.tv_sec, (int64_t)ts.tv_nsec);
 
87
    int err = clock_nanosleep(clock_id, TIMER_ABSTIME, &ts, NULL);
 
88
    if(err) {
 
89
        // maybe signal occurred, but we're going to ignore that
 
90
    }
 
91
    debugOutputExtreme(DEBUG_LEVEL_VERBOSE,
 
92
                "back with err=%d\n",
 
93
                err);
 
94
#else
 
95
    // only sleep if needed
 
96
    ffado_microsecs_t now = getCurrentTime();
 
97
    if(wake_at_usec >= now) {
 
98
        ffado_microsecs_t to_sleep = wake_at_usec - now;
 
99
        SleepUsecRelative(to_sleep);
 
100
    }
 
101
#endif
 
102
}
 
103
 
 
104
ffado_microsecs_t
 
105
SystemTimeSource::SleepUsecRandom(ffado_microsecs_t max_usec)
 
106
{
 
107
    long int rnd = random();
 
108
    long long int tmp = (rnd*max_usec);
 
109
    tmp /= RAND_MAX;
 
110
    ffado_microsecs_t usec = tmp;
 
111
    SleepUsecRelative(usec);
 
112
    return usec;
 
113
}
 
114
 
 
115
ffado_microsecs_t
 
116
SystemTimeSource::getCurrentTime()
 
117
{
 
118
    return getCurrentTimeAsUsecs();
 
119
}
 
120
 
 
121
ffado_microsecs_t
 
122
SystemTimeSource::getCurrentTimeAsUsecs()
 
123
{
 
124
    struct timespec ts;
 
125
    clock_gettime(clock_id, &ts);
 
126
    return (ffado_microsecs_t)(ts.tv_sec * 1000000LL + ts.tv_nsec / 1000LL);
 
127
}
 
128
 
 
129
} // end of namespace Util