diff options
Diffstat (limited to 'src/python-systemd/pyutil.c')
-rw-r--r-- | src/python-systemd/pyutil.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/python-systemd/pyutil.c b/src/python-systemd/pyutil.c index 79065a11c0..9510acdddb 100644 --- a/src/python-systemd/pyutil.c +++ b/src/python-systemd/pyutil.c @@ -28,3 +28,19 @@ void cleanup_Py_DECREFp(PyObject **p) { Py_DECREF(*p); } + +PyObject* absolute_timeout(uint64_t t) { + if (t == (uint64_t) -1) + return PyLong_FromLong(-1); + else { + struct timespec ts; + uint64_t n; + int msec; + + clock_gettime(CLOCK_MONOTONIC, &ts); + n = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000; + msec = t > n ? (int) ((t - n + 999) / 1000) : 0; + + return PyLong_FromLong(msec); + } +} |