Mobile API Reference  MicroStrategy 2019
AbsoluteTimeout.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : AbsoluteTimeout.h
3 // AUTHOR : vovechkin
4 // CREATION : 2005-01-20
5 // Copyright (C) MicroStrategy Incorporated 2005
6 //==============================================================================================
7 #ifndef MSynch_AbsoluteTimeout_h
8 #define MSynch_AbsoluteTimeout_h
9 
11 #include "PDCtime.h"
12 #if defined(_NO_EXCEPTION)
13 #include <stdio.h>
14 #endif
15 
16 #ifndef WIN32
17 namespace MSynch
18 {
19  inline void GetAbsoluteTimeout(struct timespec& oAbsoluteTimeout, unsigned Int32 iMilliseconds)
20  {
21  struct timeval lTimeValue;
22  const int lResult = ::gettimeofday(&lTimeValue, NULL);
23 
24  if (lResult != 0)
25  {
26 #if !defined(_NO_EXCEPTION)
27  throw ("::gettimeofday failed");
28 #else
29  printf("%s\n","::gettimeofday failed");
30  return;
31 #endif
32  }
33 
34  lTimeValue.tv_sec += iMilliseconds / 1000;
35  lTimeValue.tv_usec += (iMilliseconds % 1000) * 1000; // convert milli-seconds to micro-seconds
36 
37  if (lTimeValue.tv_usec >= 1000 * 1000)
38  {
39  // fix the micro-second overflow
40  lTimeValue.tv_sec += 1;
41  lTimeValue.tv_usec -= 1000 * 1000;
42  }
43 
44  _ASSERT(lTimeValue.tv_usec < 1000 * 1000);
45 
46  oAbsoluteTimeout.tv_sec = lTimeValue.tv_sec;
47  oAbsoluteTimeout.tv_nsec = lTimeValue.tv_usec * 1000; // convert micro-seconds to nano-seconds
48  }
49 }
50 #endif // WIN32
51 
52 #endif // MSynch_AbsoluteTimeout_h
#define _ASSERT(x)
Definition: Asserte.h:34
Definition: ReferenceCountedImpl.h:18
void GetAbsoluteTimeout(struct timespec &oAbsoluteTimeout, unsigned Int32 iMilliseconds)
Definition: AbsoluteTimeout.h:19
#define Int32
Definition: BasicTypes.h:20
#define NULL
Definition: Null.h:10