Implement TestUtils_usleep

Untested on Windows


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/e77377a6
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/e77377a6
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/e77377a6

Branch: refs/heads/master
Commit: e77377a644bd1fc394271bf818fb7c20a12fc18d
Parents: 130abe7
Author: Nick Wellnhofer <[email protected]>
Authored: Sun May 10 01:57:29 2015 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Tue May 12 20:15:25 2015 +0200

----------------------------------------------------------------------
 runtime/core/Clownfish/TestHarness/TestUtils.c  | 28 ++++++++++++++++++++
 .../core/Clownfish/TestHarness/TestUtils.cfh    |  3 +++
 2 files changed, 31 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/e77377a6/runtime/core/Clownfish/TestHarness/TestUtils.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/TestHarness/TestUtils.c 
b/runtime/core/Clownfish/TestHarness/TestUtils.c
index 3b695c9..22c9f06 100644
--- a/runtime/core/Clownfish/TestHarness/TestUtils.c
+++ b/runtime/core/Clownfish/TestHarness/TestUtils.c
@@ -117,6 +117,34 @@ TestUtils_get_str(const char *ptr) {
     return Str_new_from_utf8(ptr, strlen(ptr));
 }
 
+/********************************* WINDOWS ********************************/
+#ifdef CHY_HAS_WINDOWS_H
+
+#include <windows.h>
+
+void
+TestUtils_usleep(uint64_t microseconds) {
+    Sleep(microseconds / 1000);
+}
+
+/********************************* UNIXEN *********************************/
+#elif defined(CHY_HAS_UNISTD_H)
+
+#include <unistd.h>
+
+void
+TestUtils_usleep(uint64_t microseconds) {
+    uint32_t seconds = microseconds / 1000000;
+    microseconds %= 1000000;
+    sleep(seconds);
+    usleep(microseconds);
+}
+
+#else
+  #error "Can't find a known sleep API."
+#endif // OS switch.
+
+
 /********************************** Windows ********************************/
 #if !defined(CFISH_NOTHREADS) && defined(CHY_HAS_WINDOWS_H)
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/e77377a6/runtime/core/Clownfish/TestHarness/TestUtils.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/TestHarness/TestUtils.cfh 
b/runtime/core/Clownfish/TestHarness/TestUtils.cfh
index 6614d06..b46bf91 100644
--- a/runtime/core/Clownfish/TestHarness/TestUtils.cfh
+++ b/runtime/core/Clownfish/TestHarness/TestUtils.cfh
@@ -71,6 +71,9 @@ inert class Clownfish::TestHarness::TestUtils  {
     inert incremented String*
     random_string(size_t length);
 
+    inert void
+    usleep(uint64_t microseconds);
+
     inert cfish_Thread*
     thread_create(cfish_thread_routine_t routine, void *arg);
 

Reply via email to