Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add sleep in Process, with a Thread.sleep like use (in milliseconds/nanoseconds).
authorSamuel Lepetit <samuel.lepetit@inria.fr>
Wed, 9 May 2012 16:10:16 +0000 (18:10 +0200)
committerSamuel Lepetit <samuel.lepetit@inria.fr>
Wed, 9 May 2012 16:10:16 +0000 (18:10 +0200)
org/simgrid/msg/Process.java
src/jmsg_process.c
src/jmsg_process.h

index fa0f4af..d9cedd9 100644 (file)
@@ -309,6 +309,24 @@ public abstract class Process extends Thread {
                MsgNative.processMigrate(process, host);
                process.host = null;
        }
+       /**
+        * Makes the current process sleep until millis millisecondes have elapsed.
+        * You should note that unlike "waitFor" which takes seconds, this method takes milliseconds.
+        * FIXME: Not optimal, maybe we should have two native functions.
+        * @param millis the length of time to sleep in milliseconds.
+        */
+       public static void sleep(long millis) {
+               sleep(millis,0);
+       }
+       /**
+        * Makes the current process sleep until millis milliseconds and nanos nanoseconds 
+        * have elapsed.
+        * You should note that unlike "waitFor" which takes seconds, this method takes milliseconds and nanoseconds.
+        * Overloads Thread.sleep.
+        * @param millis the length of time to sleep in milliseconds.
+        * @param nanos additionnal nanoseconds to sleep.
+        */
+       public native static void sleep(long millis, int nanos);
        /**
         * Makes the current process sleep until time seconds have elapsed.
         * @param seconds               The time the current process must sleep.
index 9305f82..cba0649 100644 (file)
@@ -409,6 +409,16 @@ Java_org_simgrid_msg_Process_isSuspended(JNIEnv * env,
   /* true is the process is suspended, false otherwise */
   return (jboolean) MSG_process_is_suspended(process);
 }
+
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_sleep
+       (JNIEnv *env, jclass cls, jlong jmillis, jint jnanos) {
+
+       double time =  jmillis / 1000 + jnanos / 1000;
+
+       MSG_error_t rv = MSG_process_sleep(time);
+  jxbt_check_res("MSG_process_sleep()", rv, MSG_OK,
+                 bprintf("unexpected error , please report this bug"));
+}
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Process_waitFor(JNIEnv * env, jobject jprocess,
                                      jdouble jseconds)
index d4850a4..249347d 100644 (file)
@@ -301,6 +301,13 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_restart
  */
 JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Process_isSuspended
     (JNIEnv *, jobject);
+/*
+ * Class               org_simgrid_msg_Process
+ * Method              sleep
+ * Signature   (DI)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_sleep
+    (JNIEnv *, jclass, jlong, jint);
 
 /*
  * Class               org_simgrid_msg_Process