[MLton-commit] r6273

Matthew Fluet fluet at mlton.org
Fri Dec 14 22:02:09 PST 2007


Eliminate 'static struct timeval' in Time_getTimeOfDay in favor of updatable references
----------------------------------------------------------------------

U   mlton/trunk/basis-library/config/c/sys-types.sml
U   mlton/trunk/basis-library/primitive/basis-ffi.sml
U   mlton/trunk/basis-library/system/time.sml
U   mlton/trunk/runtime/basis/System/Time.c
U   mlton/trunk/runtime/basis-ffi.h
U   mlton/trunk/runtime/gen/basis-ffi.def
U   mlton/trunk/runtime/gen/basis-ffi.h
U   mlton/trunk/runtime/gen/basis-ffi.sml

----------------------------------------------------------------------

Modified: mlton/trunk/basis-library/config/c/sys-types.sml
===================================================================
--- mlton/trunk/basis-library/config/c/sys-types.sml	2007-12-15 05:21:29 UTC (rev 6272)
+++ mlton/trunk/basis-library/config/c/sys-types.sml	2007-12-15 06:02:07 UTC (rev 6273)
@@ -57,15 +57,17 @@
                        val toInt: t -> Int.int
                     end = C_SSize
 structure C_SUSeconds : sig
-                           include C_SYSTYPE
+                           include C_SYSTYPE 
+                           val castFromFixedInt: FixedInt.int -> t
                            val fromLargeInt: LargeInt.int -> t
                            val toLargeInt: t -> LargeInt.int
                         end = C_SUSeconds
 structure C_Time : sig
-                      include C_SYSTYPE
+                      include C_SYSTYPE 
+                      val castFromFixedInt: FixedInt.int -> t
                       val fromInt: Int.int -> t
+                      val fromLargeInt: LargeInt.int -> t
                       val toInt: t -> Int.int
-                      val fromLargeInt: LargeInt.int -> t
                       val toLargeInt: t -> LargeInt.int
                    end = C_Time
 structure C_UId : C_SYSTYPE = C_UId

Modified: mlton/trunk/basis-library/primitive/basis-ffi.sml
===================================================================
--- mlton/trunk/basis-library/primitive/basis-ffi.sml	2007-12-15 05:21:29 UTC (rev 6272)
+++ mlton/trunk/basis-library/primitive/basis-ffi.sml	2007-12-15 06:02:07 UTC (rev 6273)
@@ -1135,9 +1135,7 @@
 end
 structure Time = 
 struct
-val getTimeOfDay = _import "Time_getTimeOfDay" : unit -> C_Int.t;
-val sec = _import "Time_sec" : unit -> C_Time.t;
-val usec = _import "Time_usec" : unit -> C_SUSeconds.t;
+val getTimeOfDay = _import "Time_getTimeOfDay" : (C_Time.t) ref * (C_SUSeconds.t) ref -> C_Int.t;
 end
 structure Windows = 
 struct

Modified: mlton/trunk/basis-library/system/time.sml
===================================================================
--- mlton/trunk/basis-library/system/time.sml	2007-12-15 05:21:29 UTC (rev 6272)
+++ mlton/trunk/basis-library/system/time.sml	2007-12-15 06:02:07 UTC (rev 6273)
@@ -69,11 +69,15 @@
  *)
 local
    fun getNow (): time =
-      (if ~1 = Prim.getTimeOfDay ()
-          then raise Fail "Time.now"
-       else ()
-       ; timeAdd(fromSeconds (C_Time.toLargeInt (Prim.sec ())),
-                 fromMicroseconds (C_SUSeconds.toLargeInt (Prim.usec ()))))
+      let
+         val sec = ref (C_Time.castFromFixedInt 0)
+         val usec = ref (C_SUSeconds.castFromFixedInt 0)
+      in
+         if ~1 = Prim.getTimeOfDay (sec, usec)
+            then raise Fail "Time.now"
+         else timeAdd(fromSeconds (C_Time.toLargeInt (! sec)),
+                      fromMicroseconds (C_SUSeconds.toLargeInt (! usec)))
+      end
    val prev = ref (getNow ())
 in
    fun now (): time =

Modified: mlton/trunk/runtime/basis/System/Time.c
===================================================================
--- mlton/trunk/runtime/basis/System/Time.c	2007-12-15 05:21:29 UTC (rev 6272)
+++ mlton/trunk/runtime/basis/System/Time.c	2007-12-15 06:02:07 UTC (rev 6273)
@@ -1,13 +1,12 @@
 #include "platform.h"
 
-static struct timeval timeval;
-
-C_Int_t Time_getTimeOfDay (void) {
+C_Int_t Time_getTimeOfDay (Ref(C_Time_t) sec, Ref(C_SUSeconds_t) usec) {
+  struct timeval timeval;
   int res;
   res = gettimeofday (&timeval, (struct timezone*)NULL);
+  if (! res) {
+    *((C_Time_t*)sec) = timeval.tv_sec;
+    *((C_SUSeconds_t*)usec) = timeval.tv_usec;
+  }
   return res;
 }
-
-C_Time_t Time_sec (void) { return timeval.tv_sec; }
-
-C_SUSeconds_t Time_usec (void) { return timeval.tv_usec; }

Modified: mlton/trunk/runtime/basis-ffi.h
===================================================================
--- mlton/trunk/runtime/basis-ffi.h	2007-12-15 05:21:29 UTC (rev 6272)
+++ mlton/trunk/runtime/basis-ffi.h	2007-12-15 06:02:07 UTC (rev 6273)
@@ -932,9 +932,7 @@
 void Stdio_print(String8_t);
 void Stdio_printStderr(String8_t);
 void Stdio_printStdout(String8_t);
-C_Int_t Time_getTimeOfDay(void);
-C_Time_t Time_sec(void);
-C_SUSeconds_t Time_usec(void);
+C_Int_t Time_getTimeOfDay(Ref(C_Time_t),Ref(C_SUSeconds_t));
 C_Errno_t(C_PId_t) Windows_Process_create(NullString8_t,NullString8_t,NullString8_t,C_Fd_t,C_Fd_t,C_Fd_t);
 C_Errno_t(C_Int_t) Windows_Process_terminate(C_PId_t,C_Signal_t);
 MLTON_CODEGEN_STATIC_INLINE Word16_t Word16_add(Word16_t,Word16_t);

Modified: mlton/trunk/runtime/gen/basis-ffi.def
===================================================================
--- mlton/trunk/runtime/gen/basis-ffi.def	2007-12-15 05:21:29 UTC (rev 6272)
+++ mlton/trunk/runtime/gen/basis-ffi.def	2007-12-15 06:02:07 UTC (rev 6273)
@@ -822,9 +822,7 @@
 Stdio.print = _import : String8.t -> unit
 Stdio.printStderr = _import : String8.t -> unit
 Stdio.printStdout = _import : String8.t -> unit
-Time.getTimeOfDay = _import : unit -> C_Int.t
-Time.sec = _import : unit -> C_Time.t
-Time.usec = _import : unit -> C_SUSeconds.t
+Time.getTimeOfDay = _import : C_Time.t ref * C_SUSeconds.t ref -> C_Int.t
 Windows.Process.create = _import : NullString8.t * NullString8.t * NullString8.t * C_Fd.t * C_Fd.t * C_Fd.t -> C_PId.t C_Errno.t
 Windows.Process.terminate = _import : C_PId.t * C_Signal.t -> C_Int.t C_Errno.t
 ##

Modified: mlton/trunk/runtime/gen/basis-ffi.h
===================================================================
--- mlton/trunk/runtime/gen/basis-ffi.h	2007-12-15 05:21:29 UTC (rev 6272)
+++ mlton/trunk/runtime/gen/basis-ffi.h	2007-12-15 06:02:07 UTC (rev 6273)
@@ -932,9 +932,7 @@
 void Stdio_print(String8_t);
 void Stdio_printStderr(String8_t);
 void Stdio_printStdout(String8_t);
-C_Int_t Time_getTimeOfDay(void);
-C_Time_t Time_sec(void);
-C_SUSeconds_t Time_usec(void);
+C_Int_t Time_getTimeOfDay(Ref(C_Time_t),Ref(C_SUSeconds_t));
 C_Errno_t(C_PId_t) Windows_Process_create(NullString8_t,NullString8_t,NullString8_t,C_Fd_t,C_Fd_t,C_Fd_t);
 C_Errno_t(C_Int_t) Windows_Process_terminate(C_PId_t,C_Signal_t);
 MLTON_CODEGEN_STATIC_INLINE Word16_t Word16_add(Word16_t,Word16_t);

Modified: mlton/trunk/runtime/gen/basis-ffi.sml
===================================================================
--- mlton/trunk/runtime/gen/basis-ffi.sml	2007-12-15 05:21:29 UTC (rev 6272)
+++ mlton/trunk/runtime/gen/basis-ffi.sml	2007-12-15 06:02:07 UTC (rev 6273)
@@ -1135,9 +1135,7 @@
 end
 structure Time = 
 struct
-val getTimeOfDay = _import "Time_getTimeOfDay" : unit -> C_Int.t;
-val sec = _import "Time_sec" : unit -> C_Time.t;
-val usec = _import "Time_usec" : unit -> C_SUSeconds.t;
+val getTimeOfDay = _import "Time_getTimeOfDay" : (C_Time.t) ref * (C_SUSeconds.t) ref -> C_Int.t;
 end
 structure Windows = 
 struct




More information about the MLton-commit mailing list