[ovs-dev] [PATCH 3/7] util: High resolution sleep support for windows.

Bhanuprakash Bodireddy bhanuprakash.bodireddy at intel.com
Wed Nov 8 16:35:55 UTC 2017


This commit implements xnanosleep() for the threads needing high
resolution sleep timeouts in windows.

CC: Alin Gabriel Serdean <aserdean at ovn.org>
CC: Aaron Conole <aconole at redhat.com>
Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy at intel.com>
---
 lib/util.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/lib/util.c b/lib/util.c
index a29e288..46b5691 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -2217,6 +2217,23 @@ xnanosleep(uint64_t nanoseconds)
         retval = nanosleep(&ts_sleep, NULL);
         error = retval < 0 ? errno : 0;
     } while (error == EINTR);
+#else
+    HANDLE timer = CreateWaitableTimer(NULL, FALSE, "NSTIMER");
+    if (timer) {
+        LARGE_INTEGER duetime;
+        duetime.QuadPart = -nanoseconds;
+        if (SetWaitableTimer(timer, &duetime, 0, NULL, NULL, FALSE)) {
+            WaitForSingleObject(timer, INFINITE);
+            CloseHandle(timer);
+        } else {
+            CloseHandle(timer);
+            VLOG_ERR_ONCE("SetWaitableTimer Failed (%s)",
+                           ovs_lasterror_to_string());
+        }
+    } else {
+        VLOG_ERR_ONCE("CreateWaitableTimer Failed (%s)",
+                       ovs_lasterror_to_string());
+    }
 #endif
     ovsrcu_quiesce_end();
 }
-- 
2.4.11



More information about the dev mailing list