]> rtime.felk.cvut.cz Git - frescor/frsh-include.git/blobdiff - timespec_operations.h
Added the hash table for contracts
[frescor/frsh-include.git] / timespec_operations.h
index a384d2cbfa9a333b0ea589102267e2f5b0837bd6..9d6f2fe76ec64d3499af75402a8ecdfbe9898bd7 100644 (file)
@@ -183,6 +183,26 @@ static inline void msec2timespec(long msec, struct timespec *timespec)
     }
 }
 
+static inline void timespec2msec(const struct timespec *timespec, long *msec)
+{
+    *msec = 0;
+
+    /* We convert first the seconds checking for a possible overflow */
+    if (timespec->tv_sec < 2147482)
+    {
+        *msec = timespec->tv_sec*1000;
+    }
+    else
+    {
+        *msec = -1;
+        return;
+    }
+
+    /* Now we add the contribution from the msecs with a truncation */
+    *msec += (timespec->tv_nsec/1000000);
+
+}
+
 //------------------------//
 // timespec_lessthan_msec //
 //------------------------//