blob: 2ea64c9bc4a1e09487477bf8663a9681d39a8f3e [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
Victor Stinner4195b5c2012-02-08 23:03:19 +01005#include "pyconfig.h" /* include for defines */
Victor Stinner643cd682012-03-02 22:54:03 +01006#include "object.h"
Alexander Belopolsky6fc4ade2010-08-05 17:34:27 +00007
8/**************************************************************************
9Symbols and macros to supply platform-independent interfaces to time related
10functions and constants
11**************************************************************************/
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16#ifdef HAVE_GETTIMEOFDAY
17typedef struct timeval _PyTime_timeval;
18#else
19typedef struct {
20 time_t tv_sec; /* seconds since Jan. 1, 1970 */
21 long tv_usec; /* and microseconds */
22} _PyTime_timeval;
23#endif
24
25/* Similar to POSIX gettimeofday but cannot fail. If system gettimeofday
26 * fails or is not available, fall back to lower resolution clocks.
27 */
28PyAPI_FUNC(void) _PyTime_gettimeofday(_PyTime_timeval *tp);
29
Antoine Pitrou3e1fd272010-09-28 21:23:11 +000030#define _PyTime_ADD_SECONDS(tv, interval) \
31do { \
32 tv.tv_usec += (long) (((long) interval - interval) * 1000000); \
33 tv.tv_sec += (time_t) interval + (time_t) (tv.tv_usec / 1000000); \
34 tv.tv_usec %= 1000000; \
35} while (0)
36
37#define _PyTime_INTERVAL(tv_start, tv_end) \
38 ((tv_end.tv_sec - tv_start.tv_sec) + \
39 (tv_end.tv_usec - tv_start.tv_usec) * 0.000001)
40
Victor Stinner643cd682012-03-02 22:54:03 +010041#ifndef Py_LIMITED_API
42/* Convert a number of seconds, int or float, to a timespec structure.
43 nsec is always in the range [0; 999999999]. For example, -1.2 is converted
44 to (-2, 800000000). */
45PyAPI_FUNC(int) _PyTime_ObjectToTimespec(
46 PyObject *obj,
47 time_t *sec,
48 long *nsec);
49#endif
50
Alexander Belopolsky6fc4ade2010-08-05 17:34:27 +000051/* Dummy to force linking. */
52PyAPI_FUNC(void) _PyTime_Init(void);
53
54#ifdef __cplusplus
55}
56#endif
57
58#endif /* Py_PYTIME_H */
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000059#endif /* Py_LIMITED_API */