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