-/* Functions exporting the simgrid synchronization mechanisms to the Java world */
+/* Java bindings of the Synchronization API. */
-/* Copyright (c) 2012-2015. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2012-2019. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-#include <xbt/ex.hpp>
-
-#include "jmsg.h"
#include "jmsg_synchro.h"
-#include "jxbt_utilities.h"
+#include "jmsg.hpp"
+#include "jxbt_utilities.hpp"
+#include "simgrid/Exception.hpp"
#include "xbt/synchro.h"
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
-
-SG_BEGIN_DECL()
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java);
static jfieldID jsynchro_field_Mutex_bind;
xbt_mutex_t mutex = (xbt_mutex_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Mutex_bind);
try {
xbt_mutex_acquire(mutex);
- }
- catch(xbt_ex& e) {
- // Nothing to do
+ } catch (xbt_ex const& e) {
+ XBT_DEBUG("Caught an exception: %s", e.what());
}
}
msg_sem_t sem;
sem = (msg_sem_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Semaphore_bind);
- msg_error_t res = MSG_sem_acquire_timeout(sem, (double) timeout);
+ msg_error_t res = MSG_sem_acquire_timeout(sem, (double)timeout) == 0 ? MSG_OK : MSG_TIMEOUT;
if (res != MSG_OK) {
jmsg_throw_status(env, res);
}
sem = (msg_sem_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Semaphore_bind);
MSG_sem_destroy(sem);
}
-
-SG_END_DECL()