Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Properly finalize the simgrid mutexes
authorSamuel Lepetit <samuel.lepetit@inria.fr>
Thu, 3 May 2012 13:00:06 +0000 (15:00 +0200)
committerSamuel Lepetit <samuel.lepetit@inria.fr>
Thu, 3 May 2012 13:00:06 +0000 (15:00 +0200)
org/simgrid/msg/Mutex.java
src/jmsg_synchro.c
src/jmsg_synchro.h

index bf0bac7..5f88151 100644 (file)
@@ -16,7 +16,12 @@ public class Mutex {
        public Mutex(int capa) {
                init(capa);
        }
+       protected void finalize() {
+               exit();
+       }
+       private native void exit();
        private native void init(int capacity);
        public native void acquire();
        public native void release();
+       
 }
index 8cad78c..f2f06df 100644 (file)
@@ -40,3 +40,14 @@ Java_org_simgrid_msg_Mutex_release(JNIEnv * env, jobject obj) {
        mutex = (xbt_mutex_t) (long) (*env)->GetLongField(env, obj, id);
        xbt_mutex_release(mutex);
 }
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Mutex_exit(JNIEnv * env, jobject obj) {
+               xbt_mutex_t mutex;
+
+               jfieldID id = jxbt_get_sfield(env, "org/simgrid/msg/Mutex", "bind", "J");
+               if (!id) return;
+
+               mutex = (xbt_mutex_t) (long) (*env)->GetLongField(env, obj, id);
+               xbt_mutex_destroy(mutex);
+}
index 3176e35..24488a3 100644 (file)
@@ -22,5 +22,7 @@ Java_org_simgrid_msg_Mutex_acquire(JNIEnv * env, jobject obj);
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Mutex_release(JNIEnv * env, jobject obj);
 
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Mutex_exit(JNIEnv * env, jobject obj);
 
 #endif                          /* !MSG_JPROCESS_H */