aboutsummaryrefslogtreecommitdiff
path: root/nxcomp/Timestamp.h
diff options
context:
space:
mode:
authorReinhard Tartler <siretart@tauware.de>2011-11-13 09:27:52 +0100
committerReinhard Tartler <siretart@tauware.de>2011-11-13 09:27:52 +0100
commit92239dafb601d2ee5da1554d19631267c81fe57c (patch)
tree8a2b406e1d1c66c459e6c4dc3f908b60d2feacd1 /nxcomp/Timestamp.h
parentd7a8d67d760a80962821f6951caee5a9c807f5be (diff)
downloadnx-libs-92239dafb601d2ee5da1554d19631267c81fe57c.tar.gz
nx-libs-92239dafb601d2ee5da1554d19631267c81fe57c.tar.bz2
nx-libs-92239dafb601d2ee5da1554d19631267c81fe57c.zip
Imported nxcomp-3.2.0-6.tar.gznxcomp/3.2.0-6
Summary: Imported nxcomp-3.2.0-6.tar.gz Keywords: Imported nxcomp-3.2.0-6.tar.gz into Git repository
Diffstat (limited to 'nxcomp/Timestamp.h')
-rwxr-xr-xnxcomp/Timestamp.h63
1 files changed, 10 insertions, 53 deletions
diff --git a/nxcomp/Timestamp.h b/nxcomp/Timestamp.h
index 270dd3863..15246ddd5 100755
--- a/nxcomp/Timestamp.h
+++ b/nxcomp/Timestamp.h
@@ -87,20 +87,13 @@ inline T_timestamp getTimestamp(long ms)
inline long diffTimestamp(const T_timestamp &ts1, const T_timestamp &ts2)
{
- if (ts1.tv_sec == 0 && ts1.tv_usec == 0)
- {
- return -1;
- }
-
//
// Add 500 microseconds to round up
// to the nearest millisecond.
//
- long ms = ((ts2.tv_sec * 1000 + (ts2.tv_usec + 500) / 1000) -
- (ts1.tv_sec * 1000 + (ts1.tv_usec + 500) / 1000));
-
- return (ms < 0 ? -1 : ms);
+ return ((ts2.tv_sec * 1000 + (ts2.tv_usec + 500) / 1000) -
+ (ts1.tv_sec * 1000 + (ts1.tv_usec + 500) / 1000));
}
//
@@ -110,20 +103,8 @@ inline long diffTimestamp(const T_timestamp &ts1, const T_timestamp &ts2)
inline long diffUsTimestamp(const T_timestamp &ts1, const T_timestamp &ts2)
{
- if (ts1.tv_sec == 0 && ts1.tv_usec == 0)
- {
- return -1;
- }
-
- //
- // Add 500 microseconds to round up
- // to the nearest millisecond.
- //
-
- long ms = ((ts2.tv_sec * 1000000 + ts2.tv_usec) -
- (ts1.tv_sec * 1000000 + ts1.tv_usec));
-
- return (ms < 0 ? -1 : ms);
+ return ((ts2.tv_sec * 1000000 + ts2.tv_usec) -
+ (ts1.tv_sec * 1000000 + ts1.tv_usec));
}
//
@@ -234,40 +215,16 @@ inline bool isTimestamp(const T_timestamp &ts)
return 1;
}
-inline void subMsToTimestamp(T_timestamp &ts, long ms)
+inline void subMsTimestamp(T_timestamp &ts, long ms)
{
- long sec = ms / 1000;
-
- ts.tv_sec -= sec;
-
- long mod = ms % (ms * 1000);
-
- if (ts.tv_usec >= (mod * 1000))
- {
- ts.tv_sec -= mod * 1000;
- }
- else
- {
- ts.tv_sec--;
-
- ts.tv_usec = 1000000 - mod * 1000;
- }
+ ts.tv_sec -= ms / 1000;
+ ts.tv_usec -= (ms % 1000) * 1000;
}
-inline void addMsToTimestamp(T_timestamp &ts, long ms)
+inline void addMsTimestamp(T_timestamp &ts, long ms)
{
- long sec = ms / 1000;
-
- ts.tv_sec += sec;
-
- long mod = ms % (ms * 1000);
-
- ts.tv_usec += mod * 1000;
-
- if (ts.tv_usec > 1000000)
- {
- ts.tv_sec += 1;
- }
+ ts.tv_sec += ms / 1000;
+ ts.tv_usec += (ms % 1000) * 1000;
}
//