Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Check if the fields were found in Task.nativeInit and Comm.nativeInit
[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
12 JNIEXPORT void JNICALL
13 Java_org_simgrid_msg_Mutex_init(JNIEnv * env, jobject obj) {
14         xbt_mutex_t mutex = xbt_mutex_init();
15
16         jfieldID id = jxbt_get_sfield(env, "org/simgrid/msg/Mutex", "bind", "J");
17         if (!id) return;
18
19         (*env)->SetLongField(env, obj, id, (jlong) (long) (mutex));
20 }
21
22 JNIEXPORT void JNICALL
23 Java_org_simgrid_msg_Mutex_acquire(JNIEnv * env, jobject obj) {
24         xbt_mutex_t mutex;
25
26         jfieldID id = jxbt_get_sfield(env, "org/simgrid/msg/Mutex", "bind", "J");
27         if (!id) return;
28
29         mutex = (xbt_mutex_t) (long) (*env)->GetLongField(env, obj, id);
30         xbt_mutex_acquire(mutex);
31 }
32
33 JNIEXPORT void JNICALL
34 Java_org_simgrid_msg_Mutex_release(JNIEnv * env, jobject obj) {
35         xbt_mutex_t mutex;
36
37         jfieldID id = jxbt_get_sfield(env, "org/simgrid/msg/Mutex", "bind", "J");
38         if (!id) return;
39
40         mutex = (xbt_mutex_t) (long) (*env)->GetLongField(env, obj, id);
41         xbt_mutex_release(mutex);
42 }
43
44 JNIEXPORT void JNICALL
45 Java_org_simgrid_msg_Mutex_exit(JNIEnv * env, jobject obj) {
46                 xbt_mutex_t mutex;
47
48                 jfieldID id = jxbt_get_sfield(env, "org/simgrid/msg/Mutex", "bind", "J");
49                 if (!id) return;
50
51                 mutex = (xbt_mutex_t) (long) (*env)->GetLongField(env, obj, id);
52                 xbt_mutex_destroy(mutex);
53 }