[m-rev.] For review: implement time.c_clk_tck/0 for Java

James Goddard goddardjames at yahoo.com
Wed Feb 11 16:35:40 AEDT 2004


Estimated hours taken: 1.5
Branches: main

Implement some library procedures for the Java back-end.

library/time.m:
	Implement c_clk_tck/0 for Java.

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	11 Feb 2004 05:19:50 -0000
@@ -394,7 +394,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 04:19:02 -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,21 @@
 	}
 
 	return result;
+}
+
+JNIEXPORT jint JNICALL Java_mercury_runtime_Native_clk_1tck(
+		JNIEnv *env, jclass obj)
+{
+#if defined(MR_HAVE_SYSCONF) && defined(_SC_CLK_TCK)
+	return (MR_Integer) sysconf(_SC_CLK_TCK);
+#elif defined(CLK_TCK)
+	/*
+	** If sysconf is not available, try using the (obsolete) macro CLK_TCK.
+	*/
+	return (MR_Integer) CLK_TCK;
+#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