typedef simgrid::s4u::Host s4u_Host;
typedef simgrid::s4u::Link s4u_Link;
typedef simgrid::s4u::File s4u_File;
+typedef simgrid::s4u::Mutex s4u_Mutex;
typedef simgrid::s4u::Semaphore s4u_Semaphore;
typedef simgrid::s4u::Storage s4u_Storage;
typedef simgrid::s4u::NetZone s4u_NetZone;
typedef struct s4u_Host s4u_Host;
typedef struct s4u_Link s4u_Link;
typedef struct s4u_File s4u_File;
+typedef struct s4u_Mutex s4u_Mutex;
typedef struct s4u_Semaphore s4u_Semaphore;
typedef struct s4u_Storage s4u_Storage;
typedef struct s4u_NetZone s4u_NetZone;
#endif
typedef s4u_Barrier* sg_bar_t;
+typedef s4u_Mutex* sg_mutex_t;
typedef s4u_Semaphore* sg_sem_t;
typedef s4u_NetZone* sg_netzone_t;
typedef s4u_Host* sg_host_t;
#include <simgrid/host.h>
#include <simgrid/instr.h>
#include <simgrid/mailbox.h>
+#include <simgrid/mutex.h>
#include <simgrid/plugins/live_migration.h>
#include <simgrid/semaphore.h>
#include <simgrid/storage.h>
friend kernel::activity::MutexImpl;
kernel::activity::MutexImpl* const pimpl_;
- explicit Mutex(kernel::activity::MutexImpl* mutex) : pimpl_(mutex) {}
/* refcounting */
friend XBT_PUBLIC void intrusive_ptr_add_ref(Mutex* mutex);
friend XBT_PUBLIC void intrusive_ptr_release(Mutex* mutex);
public:
+ explicit Mutex(kernel::activity::MutexImpl* mutex) : pimpl_(mutex) {}
~Mutex();
// No copy:
/** You cannot create a new mutex by copying an existing one. Use MutexPtr instead */
#include "jmsg.hpp"
#include "jxbt_utilities.hpp"
#include "simgrid/Exception.hpp"
-#include "xbt/synchro.h"
+#include "simgrid/mutex.h"
+#include "simgrid/semaphore.h"
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java);
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Mutex_init(JNIEnv * env, jobject obj) {
- xbt_mutex_t mutex = xbt_mutex_init();
+ sg_mutex_t mutex = sg_mutex_init();
env->SetLongField(obj, jsynchro_field_Mutex_bind, (jlong)(uintptr_t)(mutex));
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Mutex_acquire(JNIEnv * env, jobject obj) {
- xbt_mutex_t mutex = (xbt_mutex_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Mutex_bind);
- xbt_mutex_acquire(mutex);
+ sg_mutex_t mutex = (sg_mutex_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Mutex_bind);
+ sg_mutex_lock(mutex);
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Mutex_release(JNIEnv * env, jobject obj) {
- xbt_mutex_t mutex;
+ sg_mutex_t mutex;
- mutex = (xbt_mutex_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Mutex_bind);
- xbt_mutex_release(mutex);
+ mutex = (sg_mutex_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Mutex_bind);
+ sg_mutex_unlock(mutex);
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Mutex_nativeFinalize(JNIEnv * env, jobject obj) {
- xbt_mutex_t mutex = (xbt_mutex_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Mutex_bind);
- xbt_mutex_destroy(mutex);
+ sg_mutex_t mutex = (sg_mutex_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Mutex_bind);
+ sg_mutex_destroy(mutex);
}
static jfieldID jsynchro_field_Semaphore_bind;
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Semaphore_init(JNIEnv * env, jobject obj, jint capacity) {
- msg_sem_t sem = MSG_sem_init((int) capacity);
+ sg_sem_t sem = sg_sem_init((int)capacity);
env->SetLongField(obj, jsynchro_field_Semaphore_bind, (jlong)(uintptr_t)(sem));
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Semaphore_acquire(JNIEnv * env, jobject obj, jdouble timeout) {
- msg_sem_t sem;
+ sg_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) == 0 ? MSG_OK : MSG_TIMEOUT;
+ sem = (sg_sem_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Semaphore_bind);
+ msg_error_t res = sg_sem_acquire_timeout(sem, (double)timeout) == 0 ? MSG_OK : MSG_TIMEOUT;
if (res != MSG_OK) {
jmsg_throw_status(env, res);
}
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Semaphore_release(JNIEnv * env, jobject obj) {
- msg_sem_t sem;
+ sg_sem_t sem;
- sem = (msg_sem_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Semaphore_bind);
- MSG_sem_release(sem);
+ sem = (sg_sem_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Semaphore_bind);
+ sg_sem_release(sem);
}
JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Semaphore_wouldBlock(JNIEnv * env, jobject obj) {
- msg_sem_t sem;
+ sg_sem_t sem;
- sem = (msg_sem_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Semaphore_bind);
- int res = MSG_sem_would_block(sem);
+ sem = (sg_sem_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Semaphore_bind);
+ int res = sg_sem_would_block(sem);
return (jboolean) res;
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Semaphore_nativeFinalize(JNIEnv * env, jobject obj) {
- msg_sem_t sem;
+ sg_sem_t sem;
- sem = (msg_sem_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Semaphore_bind);
- MSG_sem_destroy(sem);
+ sem = (sg_sem_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Semaphore_bind);
+ sg_sem_destroy(sem);
}
/* 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 "simgrid/forward.h"
+#include "simgrid/mutex.h"
#include "simgrid/s4u/Mutex.hpp"
#include "src/kernel/activity/MutexImpl.hpp"
} // namespace s4u
} // namespace simgrid
+
+/* **************************** Public C interface *************************** */
+sg_mutex_t sg_mutex_init()
+{
+ simgrid::kernel::activity::MutexImpl* mutex =
+ simgrid::simix::simcall([] { return new simgrid::kernel::activity::MutexImpl(); });
+
+ return new simgrid::s4u::Mutex(mutex);
+}
+
+void sg_mutex_lock(sg_mutex_t mutex)
+{
+ mutex->lock();
+}
+
+void sg_mutex_unlock(sg_mutex_t mutex)
+{
+ mutex->unlock();
+}
+
+int sg_mutex_try_lock(sg_mutex_t mutex)
+{
+ return mutex->try_lock();
+}
+
+void sg_mutex_destroy(sg_mutex_t mutex)
+{
+ delete mutex;
+}
#define BOX_NAME "box"
#ifndef DISABLE_THE_MUTEX
-static xbt_mutex_t mutex = NULL;
+static sg_mutex_t mutex = NULL;
#endif
static int receiver(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
xbt_assert(argc == 2);
char* message_name = argv[1];
#ifndef DISABLE_THE_MUTEX
- xbt_mutex_acquire(mutex);
+ sg_mutex_lock(mutex);
#endif
MSG_task_send(MSG_task_create(message_name, 0.0, 0.0, NULL), BOX_NAME);
#ifndef DISABLE_THE_MUTEX
- xbt_mutex_release(mutex);
+ sg_mutex_unlock(mutex);
#endif
return 0;
}
MSG_launch_application(argv[2]);
#ifndef DISABLE_THE_MUTEX
- mutex = xbt_mutex_init();
+ mutex = sg_mutex_init();
#endif
msg_error_t res = MSG_main();
#ifndef DISABLE_THE_MUTEX
- xbt_mutex_destroy(mutex); mutex = NULL;
+ sg_mutex_destroy(mutex);
+ mutex = NULL;
#endif
XBT_INFO("Simulation time %g", MSG_get_clock());
include/simgrid/kernel/future.hpp
include/simgrid/host.h
include/simgrid/link.h
+ include/simgrid/mutex.h
include/simgrid/semaphore.h
include/simgrid/storage.h
include/simgrid/vm.h