~mterry/qtmir/warn-on-xapp

« back to all changes in this revision

Viewing changes to src/common/timestamp_impl.h

  • Committer: CI Train Bot
  • Author(s): Nick Dedekind
  • Date: 2015-10-21 11:46:54 UTC
  • mfrom: (369.4.13 qtmir)
  • Revision ID: ci-train-bot@canonical.com-20151021114654-zxs13246bxcdci9l
Added touch performance tracing and test.
Approved by: Gerry Boland

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <QCoreApplication>
 
2
#include <QVariant>
 
3
 
 
4
extern "C" {
 
5
        void resetStartTime(std::chrono::nanoseconds timestamp);
 
6
        std::chrono::nanoseconds getStartTime(std::chrono::nanoseconds timestamp, bool allowReset = true);
 
7
}
 
8
 
 
9
namespace qtmir {
 
10
 
 
11
template<typename T>
 
12
T compressTimestamp(std::chrono::nanoseconds timestamp)
 
13
{
 
14
    std::chrono::nanoseconds startTime = getStartTime(timestamp);
 
15
    std::chrono::nanoseconds result = timestamp - startTime;
 
16
 
 
17
    if (std::numeric_limits<std::chrono::nanoseconds::rep>::max() > std::numeric_limits<T>::max() &&
 
18
        result > std::chrono::nanoseconds(std::numeric_limits<T>::max())) {
 
19
        // we've overflowed the boundaries of the millisecond type.
 
20
        resetStartTime(timestamp);
 
21
        return 0;
 
22
    }
 
23
 
 
24
    return result.count();
 
25
}
 
26
 
 
27
template<typename T>
 
28
std::chrono::nanoseconds uncompressTimestamp(T timestamp)
 
29
{
 
30
    auto tsNS = std::chrono::nanoseconds(timestamp);
 
31
    return getStartTime(tsNS, false) + std::chrono::nanoseconds(tsNS);
 
32
}
 
33
 
 
34
}
 
 
b'\\ No newline at end of file'