Przeglądaj źródła

cmTime.h/c : Added cmTimeDiffMicros(),cmTimeIsLTE(),cmTimeIsGTE(),cmTimeIsEqual(),cmTimeIsZero(),cmTimeSetZero().

master
kevin 11 lat temu
rodzic
commit
e11e660e52
2 zmienionych plików z 62 dodań i 5 usunięć
  1. 45
    5
      cmTime.c
  2. 17
    0
      cmTime.h

+ 45
- 5
cmTime.c Wyświetl plik

@@ -62,12 +62,52 @@ unsigned cmTimeElapsedMicros( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 )
62 62
 
63 63
 unsigned cmTimeAbsElapsedMicros( const cmTimeSpec_t*  t0, const cmTimeSpec_t* t1 )
64 64
 {
65
-  if( t1->tv_sec > t0->tv_sec )
65
+  if( cmTimeIsLTE(t0,t1) )
66 66
     return cmTimeElapsedMicros(t0,t1);
67 67
 
68
-  if( t1->tv_sec == t0->tv_sec )
69
-    if( t1->tv_nsec > t0->tv_nsec )
70
-      return cmTimeElapsedMicros(t0,t1);
71
-
72 68
   return cmTimeElapsedMicros(t1,t0);
73 69
 }
70
+
71
+int cmTimeDiffMicros( const cmTimeSpec_t*  t0, const cmTimeSpec_t* t1 )
72
+{
73
+  if( cmTimeIsLTE(t0,t1) )
74
+    return cmTimeElapsedMicros(t0,t1);
75
+
76
+  return -((int)cmTimeElapsedMicros(t1,t0));
77
+}
78
+
79
+bool cmTimeIsLTE( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 )
80
+{
81
+  if( t0->tv_sec  < t1->tv_sec )
82
+    return true;
83
+
84
+  if( t0->tv_sec == t1->tv_sec )
85
+    return t0->tv_nsec <= t1->tv_nsec;
86
+
87
+  return false; 
88
+}
89
+
90
+bool cmTimeIsGTE( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 )
91
+{
92
+  if( t0->tv_sec  > t1->tv_sec )
93
+    return true;
94
+
95
+  if( t0->tv_sec == t1->tv_sec )
96
+    return t0->tv_nsec >= t1->tv_nsec;
97
+
98
+  return false;   
99
+}
100
+
101
+bool cmTimeIsEqual( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 )
102
+{ return t0->tv_sec==t1->tv_sec && t0->tv_nsec==t1->tv_nsec; }
103
+
104
+bool cmTimeIsZero( const cmTimeSpec_t* t0 )
105
+{ return t0->tv_sec==0  && t0->tv_nsec==0; }
106
+
107
+void cmTimeSetZero( cmTimeSpec_t* t0 )
108
+{
109
+  t0->tv_sec = 0;
110
+  t0->tv_nsec = 0;
111
+}
112
+
113
+

+ 17
- 0
cmTime.h Wyświetl plik

@@ -33,6 +33,23 @@ extern "C" {
33 33
   // The function therefore begins by swapping t1 and t0 if t0 is after t1.
34 34
   unsigned cmTimeAbsElapsedMicros( const cmTimeSpec_t*  t0, const cmTimeSpec_t* t1 ); 
35 35
 
36
+
37
+  // Same as cmTimeElapsedMicros() but returns a negative value if t0 is after t1.
38
+  int cmTimeDiffMicros( const cmTimeSpec_t*  t0, const cmTimeSpec_t* t1 );
39
+
40
+
41
+  // Returns true if t0 <=  t1.
42
+  bool cmTimeIsLTE( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 );
43
+
44
+  // Return true if t0 >= t1.
45
+  bool cmTimeIsGTE( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 );
46
+
47
+  bool cmTimeIsEqual( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 );
48
+
49
+  bool cmTimeIsZero( const cmTimeSpec_t* t0 );
50
+
51
+  void cmTimeSetZero( cmTimeSpec_t* t0 );
52
+
36 53
   //)
37 54
   //}
38 55
 

Ładowanie…
Anuluj
Zapisz