MSG semaphores become legacy as they are now implemented through S4U.
typedef simgrid::s4u::Host s4u_Host;
typedef simgrid::s4u::Link s4u_Link;
typedef simgrid::s4u::File s4u_File;
+typedef simgrid::s4u::Semaphore s4u_Semaphore;
typedef simgrid::s4u::Storage s4u_Storage;
typedef simgrid::s4u::NetZone s4u_NetZone;
typedef simgrid::s4u::VirtualMachine s4u_VM;
typedef struct s4u_Host s4u_Host;
typedef struct s4u_Link s4u_Link;
typedef struct s4u_File s4u_File;
+typedef struct s4u_Semaphore s4u_Semaphore;
typedef struct s4u_Storage s4u_Storage;
typedef struct s4u_NetZone s4u_NetZone;
typedef struct s4u_VM s4u_VM;
#endif
typedef s4u_Barrier* sg_bar_t;
+typedef s4u_Semaphore* sg_sem_t;
typedef s4u_NetZone* sg_netzone_t;
typedef s4u_Host* sg_host_t;
typedef s4u_Link* sg_link_t;
#include <simgrid/instr.h>
#include <simgrid/mailbox.h>
#include <simgrid/plugins/live_migration.h>
+#include <simgrid/semaphore.h>
#include <simgrid/storage.h>
#include <simgrid/vm.h>
#include <simgrid/zone.h>
*/
XBT_PUBLIC void MSG_mailbox_set_async(const char* alias);
-/** @brief Opaque type representing a semaphore
- * @hideinitializer
- */
-typedef struct s_smx_sem_t* msg_sem_t; // Yeah that's a rename of the smx_sem_t which doesnt require smx_sem_t to be
- // declared here
+/** @brief Opaque type representing a semaphore */
+typedef sg_sem_t msg_sem_t;
XBT_PUBLIC msg_sem_t MSG_sem_init(int initial_value);
XBT_PUBLIC void MSG_sem_acquire(msg_sem_t sem);
-XBT_PUBLIC msg_error_t MSG_sem_acquire_timeout(msg_sem_t sem, double timeout);
+XBT_PUBLIC int MSG_sem_acquire_timeout(msg_sem_t sem, double timeout);
XBT_PUBLIC void MSG_sem_release(msg_sem_t sem);
XBT_PUBLIC int MSG_sem_get_capacity(msg_sem_t sem);
XBT_PUBLIC void MSG_sem_destroy(msg_sem_t sem);
smx_sem_t sem_;
std::atomic_int_fast32_t refcount_{0};
- explicit Semaphore(unsigned int initial_capacity);
- ~Semaphore();
-
friend void intrusive_ptr_add_ref(Semaphore* sem);
friend void intrusive_ptr_release(Semaphore* sem);
public:
+ explicit Semaphore(unsigned int initial_capacity);
+ ~Semaphore();
+
// No copy:
/** You cannot create a new semaphore by copying an existing one. Use SemaphorePtr instead */
Semaphore(Semaphore const&) = delete;
static SemaphorePtr create(unsigned int initial_capacity);
void acquire();
+ int acquire_timeout(double timeout);
void release();
+ int get_capacity();
+ int would_block();
};
}} // namespace simgrid::s4u
--- /dev/null
+/* Public interface to the Link datatype */
+
+/* Copyright (c) 2018. 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. */
+
+#ifndef INCLUDE_SIMGRID_SEMAPHORE_H_
+#define INCLUDE_SIMGRID_SEMAPHORE_H_
+
+#include <simgrid/forward.h>
+
+/* C interface */
+SG_BEGIN_DECL()
+XBT_PUBLIC sg_sem_t sg_sem_init(int initial_value);
+XBT_PUBLIC void sg_sem_acquire(sg_sem_t sem);
+XBT_PUBLIC int sg_sem_acquire_timeout(sg_sem_t sem, double timeout);
+XBT_PUBLIC void sg_sem_release(sg_sem_t sem);
+XBT_PUBLIC int sg_sem_get_capacity(sg_sem_t sem);
+XBT_PUBLIC void sg_sem_destroy(sg_sem_t sem);
+XBT_PUBLIC int sg_sem_would_block(sg_sem_t sem);
+
+SG_END_DECL()
+
+#endif /* INCLUDE_SIMGRID_SEMAPHORE_H_ */
{
return sg_barrier_wait(bar);
}
+
+sg_sem_t MSG_sem_init(int initial_value)
+{
+ return sg_sem_init(initial_value);
+}
+void MSG_sem_acquire(sg_sem_t sem)
+{
+ sg_sem_acquire(sem);
+}
+int MSG_sem_acquire_timeout(sg_sem_t sem, double timeout)
+{
+ sg_sem_acquire_timeout(sem, timeout);
+}
+void MSG_sem_release(sg_sem_t sem)
+{
+ sg_sem_release(sem);
+}
+int MSG_sem_get_capacity(sg_sem_t sem)
+{
+ return sg_sem_get_capacity(sem);
+}
+void MSG_sem_destroy(sg_sem_t sem)
+{
+ sg_sem_destroy(sem);
+}
+int MSG_sem_would_block(sg_sem_t sem)
+{
+ return sg_sem_would_block(sem);
+}
+++ /dev/null
-/* Copyright (c) 2013-2018. 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 "msg_private.hpp"
-#include "simgrid/Exception.hpp"
-#include "src/simix/smx_private.hpp"
-#include "src/simix/smx_synchro_private.hpp"
-#include "xbt/synchro.h"
-
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_synchro, msg, "Logging specific to MSG (synchro)");
-
-/** @addtogroup msg_synchro
- *
- * @{
- */
-
-/** @brief creates a semaphore object of the given initial capacity */
-msg_sem_t MSG_sem_init(int initial_value) {
- return simgrid::simix::simcall([initial_value] { return SIMIX_sem_init(initial_value); });
-}
-
-/** @brief locks on a semaphore object */
-void MSG_sem_acquire(msg_sem_t sem) {
- simcall_sem_acquire(sem);
-}
-
-/** @brief locks on a semaphore object up until the provided timeout expires */
-msg_error_t MSG_sem_acquire_timeout(msg_sem_t sem, double timeout) {
- return simcall_sem_acquire_timeout(sem, timeout) ? MSG_TIMEOUT : MSG_OK;
-}
-
-/** @brief releases the semaphore object */
-void MSG_sem_release(msg_sem_t sem) {
- simgrid::simix::simcall([sem] { SIMIX_sem_release(sem); });
-}
-
-int MSG_sem_get_capacity(msg_sem_t sem) {
- return simgrid::simix::simcall([sem] { return SIMIX_sem_get_capacity(sem); });
-}
-
-void MSG_sem_destroy(msg_sem_t sem) {
- SIMIX_sem_destroy(sem);
-}
-
-/** @brief returns a boolean indicating if this semaphore would block at this very specific time
- *
- * Note that the returned value may be wrong right after the function call, when you try to use it...
- * But that's a classical semaphore issue, and SimGrid's semaphore are not different to usual ones here.
- */
-int MSG_sem_would_block(msg_sem_t sem) {
- return simgrid::simix::simcall([sem] { return SIMIX_sem_would_block(sem); });
-}
-
-/**@}*/
#include "src/simix/smx_synchro_private.hpp"
#include "xbt/log.h"
+#include "simgrid/forward.h"
#include "simgrid/s4u/Semaphore.hpp"
namespace simgrid {
simcall_sem_acquire(sem_);
}
+int Semaphore::acquire_timeout(double timeout)
+{
+ return simcall_sem_acquire_timeout(sem_, timeout);
+}
+
void Semaphore::release()
{
simgrid::simix::simcall([this] { SIMIX_sem_release(sem_); });
}
+int Semaphore::get_capacity()
+{
+ return simgrid::simix::simcall([this] { return SIMIX_sem_get_capacity(sem_); });
+}
+
+int Semaphore::would_block()
+{
+ return simgrid::simix::simcall([this] { return SIMIX_sem_would_block(sem_); });
+}
+
void intrusive_ptr_add_ref(Semaphore* sem)
{
xbt_assert(sem);
}
}
+/* **************************** Public C interface *************************** */
+/** @brief creates a semaphore object of the given initial capacity */
+sg_sem_t sg_sem_init(int initial_value)
+{
+ return new simgrid::s4u::Semaphore(initial_value);
+}
+
+/** @brief locks on a semaphore object */
+void sg_sem_acquire(sg_sem_t sem)
+{
+ sem->acquire();
+}
+
+/** @brief locks on a semaphore object up until the provided timeout expires */
+int sg_sem_acquire_timeout(sg_sem_t sem, double timeout)
+{
+ return sem->acquire_timeout(timeout);
+}
+
+/** @brief releases the semaphore object */
+void sg_sem_release(sg_sem_t sem)
+{
+ sem->release();
+}
+
+int sg_sem_get_capacity(sg_sem_t sem)
+{
+ return sem->get_capacity();
+}
+
+void sg_sem_destroy(sg_sem_t sem)
+{
+ delete sem;
+}
+
+/** @brief returns a boolean indicating if this semaphore would block at this very specific time
+ *
+ * Note that the returned value may be wrong right after the function call, when you try to use it...
+ * But that's a classical semaphore issue, and SimGrid's semaphore are not different to usual ones here.
+ */
+int sg_sem_would_block(sg_sem_t sem)
+{
+ return sem->would_block();
+}
src/msg/msg_gos.cpp
src/msg/msg_legacy.cpp
src/msg/msg_process.cpp
- src/msg/msg_synchro.cpp
src/msg/msg_task.cpp
)
include/simgrid/kernel/future.hpp
include/simgrid/host.h
include/simgrid/link.h
+ include/simgrid/semaphore.h
include/simgrid/storage.h
include/simgrid/vm.h
include/simgrid/zone.h