| Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 1 | #ifndef Py_LIMITED_API | 
| Alexander Belopolsky | 6fc4ade | 2010-08-05 17:34:27 +0000 | [diff] [blame] | 2 | #ifndef Py_PYTIME_H | 
 | 3 | #define Py_PYTIME_H | 
 | 4 |  | 
 | 5 | #include "pyconfig.h" /* include for defines */ | 
 | 6 |  | 
 | 7 | /************************************************************************** | 
 | 8 | Symbols and macros to supply platform-independent interfaces to time related | 
 | 9 | functions and constants | 
 | 10 | **************************************************************************/ | 
 | 11 | #ifdef __cplusplus | 
 | 12 | extern "C" { | 
 | 13 | #endif | 
 | 14 |  | 
 | 15 | #ifdef HAVE_GETTIMEOFDAY | 
 | 16 | typedef struct timeval _PyTime_timeval; | 
 | 17 | #else | 
 | 18 | typedef struct { | 
 | 19 |     time_t       tv_sec;   /* seconds since Jan. 1, 1970 */ | 
 | 20 |     long         tv_usec;  /* and microseconds */ | 
 | 21 | } _PyTime_timeval; | 
 | 22 | #endif | 
 | 23 |  | 
 | 24 | /* Similar to POSIX gettimeofday but cannot fail.  If system gettimeofday | 
 | 25 |  * fails or is not available, fall back to lower resolution clocks. | 
 | 26 |  */ | 
 | 27 | PyAPI_FUNC(void) _PyTime_gettimeofday(_PyTime_timeval *tp); | 
 | 28 |  | 
| Antoine Pitrou | 3e1fd27 | 2010-09-28 21:23:11 +0000 | [diff] [blame] | 29 | #define _PyTime_ADD_SECONDS(tv, interval) \ | 
 | 30 | do { \ | 
 | 31 |     tv.tv_usec += (long) (((long) interval - interval) * 1000000); \ | 
 | 32 |     tv.tv_sec += (time_t) interval + (time_t) (tv.tv_usec / 1000000); \ | 
 | 33 |     tv.tv_usec %= 1000000; \ | 
 | 34 | } while (0) | 
 | 35 |  | 
 | 36 | #define _PyTime_INTERVAL(tv_start, tv_end) \ | 
 | 37 |     ((tv_end.tv_sec - tv_start.tv_sec) + \ | 
 | 38 |      (tv_end.tv_usec - tv_start.tv_usec) * 0.000001) | 
 | 39 |  | 
| Alexander Belopolsky | 6fc4ade | 2010-08-05 17:34:27 +0000 | [diff] [blame] | 40 | /* Dummy to force linking. */ | 
 | 41 | PyAPI_FUNC(void) _PyTime_Init(void); | 
 | 42 |  | 
 | 43 | #ifdef __cplusplus | 
 | 44 | } | 
 | 45 | #endif | 
 | 46 |  | 
 | 47 | #endif /* Py_PYTIME_H */ | 
| Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 48 | #endif /* Py_LIMITED_API */ |