blob: d707bdb9a87c7c31cec598fab828f86a8c3ef217 [file] [log] [blame]
Martin v. Löwis4d0d4712010-12-03 20:14:31 +00001#ifndef Py_LIMITED_API
Alexander Belopolsky6fc4ade2010-08-05 17:34:27 +00002#ifndef Py_PYTIME_H
3#define Py_PYTIME_H
4
5#include "pyconfig.h" /* include for defines */
6
7/**************************************************************************
8Symbols and macros to supply platform-independent interfaces to time related
9functions and constants
10**************************************************************************/
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#ifdef HAVE_GETTIMEOFDAY
16typedef struct timeval _PyTime_timeval;
17#else
18typedef 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 */
27PyAPI_FUNC(void) _PyTime_gettimeofday(_PyTime_timeval *tp);
28
Antoine Pitrou3e1fd272010-09-28 21:23:11 +000029#define _PyTime_ADD_SECONDS(tv, interval) \
30do { \
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 Belopolsky6fc4ade2010-08-05 17:34:27 +000040/* Dummy to force linking. */
41PyAPI_FUNC(void) _PyTime_Init(void);
42
43#ifdef __cplusplus
44}
45#endif
46
47#endif /* Py_PYTIME_H */
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000048#endif /* Py_LIMITED_API */