Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a cache on Host.name. Add a cache on some jfieldID/jmethodID on Host/Process
[simgrid.git] / src / jmsg_synchro.c
1 /* Functions exporting the simgrid synchronization mechanisms to the Java world */
2
3 /* Copyright (c) 2012. The SimGrid Team. All rights reserved.                   */
4
5 /* This program is free software; you can redistribute it and/or modify it
6   * under the terms of the license (GNU LGPL) which comes with this package.    */
7
8 #include "jmsg_synchro.h"
9 #include "jxbt_utilities.h"
10
11 JNIEXPORT void JNICALL
12 Java_org_simgrid_msg_Mutex_init(JNIEnv * env, jobject obj) {
13         xbt_mutex_t mutex = xbt_mutex_init();
14
15         jfieldID id = jxbt_get_sfield(env, "org/simgrid/msg/Mutex", "bind", "J");
16         if (!id) return;
17
18         (*env)->SetLongField(env, obj, id, (jlong) (long) (mutex));
19 }
20
21 JNIEXPORT void JNICALL
22 Java_org_simgrid_msg_Mutex_acquire(JNIEnv * env, jobject obj) {
23         xbt_mutex_t mutex;
24
25         jfieldID id = jxbt_get_sfield(env, "org/simgrid/msg/Mutex", "bind", "J");
26         if (!id) return;
27
28         mutex = (xbt_mutex_t) (long) (*env)->GetLongField(env, obj, id);
29         xbt_mutex_acquire(mutex);
30 }
31
32 JNIEXPORT void JNICALL
33 Java_org_simgrid_msg_Mutex_release(JNIEnv * env, jobject obj) {
34         xbt_mutex_t mutex;
35
36         jfieldID id = jxbt_get_sfield(env, "org/simgrid/msg/Mutex", "bind", "J");
37         if (!id) return;
38
39         mutex = (xbt_mutex_t) (long) (*env)->GetLongField(env, obj, id);
40         xbt_mutex_release(mutex);
41 }
42
43 JNIEXPORT void JNICALL
44 Java_org_simgrid_msg_Mutex_exit(JNIEnv * env, jobject obj) {
45                 xbt_mutex_t mutex;
46
47                 jfieldID id = jxbt_get_sfield(env, "org/simgrid/msg/Mutex", "bind", "J");
48                 if (!id) return;
49
50                 mutex = (xbt_mutex_t) (long) (*env)->GetLongField(env, obj, id);
51                 xbt_mutex_destroy(mutex);
52 }