summaryrefslogtreecommitdiff
path: root/clock.py
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2013-03-17 12:16:07 +0100
committerChristian Franke <nobody@nowhere.ws>2013-03-17 12:22:03 +0100
commit76c0532b5638eda76e71a748832290adb985f21a (patch)
treea8e86383c7125d46bd07319f723ada7805c41c8e /clock.py
parent51f72b53d686e4f6f6fcd83356d0bcb920411487 (diff)
Add some queue management to osc2light gateway
Diffstat (limited to 'clock.py')
-rw-r--r--clock.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/clock.py b/clock.py
new file mode 100644
index 0000000..3e97dbf
--- /dev/null
+++ b/clock.py
@@ -0,0 +1,23 @@
+# Courtesy of Armin Ronacher, found at StackOverflow
+
+import ctypes
+import os
+
+CLOCK_MONOTONIC = 1 # see <linux/time.h>
+
+class timespec(ctypes.Structure):
+ _fields_ = [
+ ('tv_sec', ctypes.c_long),
+ ('tv_nsec', ctypes.c_long)
+ ]
+
+librt = ctypes.CDLL('librt.so.1', use_errno=True)
+clock_gettime = librt.clock_gettime
+clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]
+
+def now():
+ t = timespec()
+ if clock_gettime(CLOCK_MONOTONIC, ctypes.pointer(t)) != 0:
+ errno_ = ctypes.get_errno()
+ raise OSError(errno_, os.strerror(errno_))
+ return t.tv_sec + t.tv_nsec * 1e-9