From: Samuel Lepetit Date: Thu, 3 May 2012 13:00:06 +0000 (+0200) Subject: Properly finalize the simgrid mutexes X-Git-Tag: v3_9_90~569^2~19^2~112 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/78224183a24a35d071d26d0653d7d3c196b131e6 Properly finalize the simgrid mutexes --- diff --git a/org/simgrid/msg/Mutex.java b/org/simgrid/msg/Mutex.java index bf0bac7d02..5f88151904 100644 --- a/org/simgrid/msg/Mutex.java +++ b/org/simgrid/msg/Mutex.java @@ -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(); + } diff --git a/src/jmsg_synchro.c b/src/jmsg_synchro.c index 8cad78cd79..f2f06dffa0 100644 --- a/src/jmsg_synchro.c +++ b/src/jmsg_synchro.c @@ -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); +} diff --git a/src/jmsg_synchro.h b/src/jmsg_synchro.h index 3176e35cbd..24488a37cf 100644 --- a/src/jmsg_synchro.h +++ b/src/jmsg_synchro.h @@ -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 */