[m-rev.] diff: Java implementation of time.clk_tck

James Goddard goddardjames at yahoo.com
Thu Feb 12 13:25:43 AEDT 2004


Estimated hours taken: 2
Branches: main

Implement some library procedures for the Java back-end.

library/time.m:
	Implement c_clk_tck/0 for Java.  Also changed the C implementation to
	use the same macro as that used in Native.c.

java/runtime/Native.java.in:
	Add new function clk_tck() to be called by c_clk_tck/0.

java/runtime/Native.c:
	Add corresponding implementation for clk_tck().


Index: time.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/time.m,v
retrieving revision 1.41
diff -u -d -r1.41 time.m
--- time.m	5 Feb 2004 03:56:04 -0000	1.41
+++ time.m	12 Feb 2004 02:19:37 -0000
@@ -375,13 +375,8 @@
 	time__c_clk_tck = (Ret::out),
 	[will_not_call_mercury, promise_pure],
 "{
-#if defined(MR_HAVE_SYSCONF) && defined(_SC_CLK_TCK)
-	Ret = (MR_Integer) sysconf(_SC_CLK_TCK);
-#elif defined(CLK_TCK)
-	/*
-	** If sysconf is not available, try using the (obsolete) macro CLK_TCK.
-	*/
-	Ret = (MR_Integer) CLK_TCK;
+#if defined(MR_CLOCK_TICKS_PER_SECOND)
+	Ret = MR_CLOCK_TICKS_PER_SECOND;
 #else
 	Ret = -1;
 #endif
@@ -394,7 +389,18 @@
 	// TicksPerSecond is guaranteed to be 10,000,000
 	Ret = (int) System.TimeSpan.TicksPerSecond;
 }").
-% XXX Java implementation still to come, will require some native code.
+:- pragma foreign_proc("Java", time__c_clk_tck = (Ret::out),
+	[will_not_call_mercury, promise_pure],
+"
+	if (mercury.runtime.Native.isAvailable()) {
+		Ret = mercury.runtime.Native.clk_tck();
+	} else {
+		throw new java.lang.RuntimeException(
+				""time__clk_tck is not implemented "" +
+				""in pure Java.  Native dynamic link "" +
+				""library is required."");
+	}
+").
 
 %-----------------------------------------------------------------------------%
 
Index: ../java/runtime/Native.java.in
===================================================================
RCS file: /home/mercury1/repository/mercury/java/runtime/Native.java.in,v
retrieving revision 1.2
diff -u -d -r1.2 Native.java.in
--- ../java/runtime/Native.java.in	11 Feb 2004 03:05:14 -0000	1.2
+++ ../java/runtime/Native.java.in	11 Feb 2004 04:14:34 -0000
@@ -128,6 +128,15 @@
 	public static native int[] times();
 
 	/*
+	** clk_tck():
+	**	Returns the number of "clock ticks" per second as defined by
+	**	sysconf(_SC_CLK_TCK).  A `clock_t' value returned by
+	**	'times()' can be divided by this value to obtain a time in
+	**	seconds.
+	*/
+	public static native int clk_tck();
+
+	/*
 	** get_user_cpu_miliseconds():
 	**	Native method to return the CPU time consumed by the process,
 	**	in miliseconds, from an arbitrary initial time.
Index: ../java/runtime/Native.c
===================================================================
RCS file: /home/mercury1/repository/mercury/java/runtime/Native.c,v
retrieving revision 1.1
diff -u -d -r1.1 Native.c
--- ../java/runtime/Native.c	5 Feb 2004 03:56:01 -0000	1.1
+++ ../java/runtime/Native.c	11 Feb 2004 23:58:11 -0000
@@ -35,6 +35,13 @@
 
 /*
  * Class:     Native
+ * Method:    clk_tck
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_mercury_runtime_Native_clk_1tck(JNIEnv *, jclass);
+
+/*
+ * Class:     Native
  * Method:    get_user_cpu_miliseconds
  * Signature: ()I
  */
@@ -88,6 +95,16 @@
 	}
 
 	return result;
+}
+
+JNIEXPORT jint JNICALL Java_mercury_runtime_Native_clk_1tck(
+		JNIEnv *env, jclass obj)
+{
+#if defined(MR_CLOCK_TICKS_PER_SECOND)
+	return MR_CLOCK_TICKS_PER_SECOND;
+#else
+	return -1;
+#endif
 }
 
 JNIEXPORT jint JNICALL
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list