runtime/plc_Win32_main.c
changeset 49 45dc6a944ab6
child 57 3b53f9a509d9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/runtime/plc_Win32_main.c	Fri Sep 21 17:48:34 2007 +0200
@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <sys/timeb.h>
+#include <time.h>
+#include <windows.h>
+
+void timer_notify()
+{
+   struct _timeb timebuffer;
+
+   _ftime( &timebuffer );
+   CURRENT_TIME.tv_sec = timebuffer.time;
+   CURRENT_TIME.tv_nsec = timebuffer.millitm * 1000000
+   __run();
+}
+
+int main(int argc,char **argv)
+{
+    HANDLE hTimer = NULL;
+    LARGE_INTEGER liDueTime;
+
+    liDueTime.QuadPart = -10000 * maxval(common_ticktime__,1);;
+
+    // Create a waitable timer.
+    hTimer = CreateWaitableTimer(NULL, TRUE, "WaitableTimer");
+    if (NULL == hTimer)
+    {
+        printf("CreateWaitableTimer failed (%d)\n", GetLastError());
+        return 1;
+    }
+
+    __init();
+
+    // Set a timer to wait for 10 seconds.
+    if (!SetWaitableTimer(hTimer, &liDueTime, common_ticktime__, NULL, NULL, 0))
+    {
+        printf("SetWaitableTimer failed (%d)\n", GetLastError());
+        return 2;
+    }
+
+    while(1){
+    // Wait for the timer.
+        if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0)
+        {
+            printf("WaitForSingleObject failed (%d)\n", GetLastError());
+            break;
+        }
+        timer_notify();
+    }
+
+    __cleanup();
+
+    return 0;
+}