~3v1n0/unity/overlay-border-scale

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/TimeUtil.h

  • Committer: Daniel van Vugt
  • Date: 2012-03-14 06:24:18 UTC
  • mfrom: (2108 unity)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: daniel.van.vugt@canonical.com-20120314062418-nprucpbr0m7qky5e
MergedĀ latestĀ lp:unity

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
class TimeUtil
26
26
{
27
27
public:
28
 
static int TimeDelta (struct timespec const* x, struct timespec const* y);
 
28
  static int TimeDelta (struct timespec const* x, struct timespec const* y)
 
29
  {
 
30
    return ((x->tv_sec - y->tv_sec) * 1000) + ((x->tv_nsec - y->tv_nsec) / 1000000);
 
31
  }
 
32
 
 
33
  static void SetTimeStruct(struct timespec* timer, struct timespec* sister = 0, int sister_relation = 0)
 
34
  {
 
35
    struct timespec current;
 
36
    clock_gettime(CLOCK_MONOTONIC, &current);
 
37
 
 
38
    if (sister)
 
39
    {
 
40
      int diff = TimeDelta(&current, sister);
 
41
 
 
42
      if (diff < sister_relation)
 
43
      {
 
44
        int remove = sister_relation - diff;
 
45
        SetTimeBack(&current, remove);
 
46
      }
 
47
    }
 
48
 
 
49
    timer->tv_sec = current.tv_sec;
 
50
    timer->tv_nsec = current.tv_nsec;
 
51
  }
 
52
 
 
53
  static void SetTimeBack(struct timespec* timeref, int remove)
 
54
  {
 
55
    timeref->tv_sec -= remove / 1000;
 
56
    remove = remove % 1000;
 
57
 
 
58
    if (remove > timeref->tv_nsec / 1000000)
 
59
    {
 
60
      timeref->tv_sec--;
 
61
      timeref->tv_nsec += 1000000000;
 
62
    }
 
63
    timeref->tv_nsec -= remove * 1000000;
 
64
  }
29
65
};
30
66
 
31
 
inline 
32
 
int TimeUtil::TimeDelta (struct timespec const* x, struct timespec const* y)
33
 
{
34
 
  return ((x->tv_sec - y->tv_sec) * 1000) + ((x->tv_nsec - y->tv_nsec) / 1000000);
35
 
}
36
67
 
37
68
}