#define SIMIX_SYNCHRO_PRIVATE_H
#include "simgrid/s4u/ConditionVariable.hpp"
-#include "xbt/swag.h"
+#include "src/simix/ActorImpl.hpp"
+#include <boost/intrusive/list.hpp>
namespace simgrid {
namespace simix {
+typedef boost::intrusive::list<ActorImpl, boost::intrusive::member_hook<ActorImpl, boost::intrusive::list_member_hook<>,
+ &ActorImpl::smx_synchro_hook>>
+ SynchroList;
+
class XBT_PUBLIC() MutexImpl {
public:
MutexImpl();
bool locked = false;
smx_actor_t owner = nullptr;
// List of sleeping processes:
- xbt_swag_t sleeping = nullptr;
+ simgrid::simix::SynchroList sleeping;
// boost::intrusive_ptr<Mutex> support:
friend void intrusive_ptr_add_ref(MutexImpl* mutex)
{
- // Atomic operation! Do not split in two instructions!
- XBT_ATTRIB_UNUSED auto previous = (mutex->refcount_)++;
+ XBT_ATTRIB_UNUSED auto previous = mutex->refcount_.fetch_add(1);
xbt_assert(previous != 0);
}
friend void intrusive_ptr_release(MutexImpl* mutex)
{
- // Atomic operation! Do not split in two instructions!
- auto count = --(mutex->refcount_);
- if (count == 0)
+ if (mutex->refcount_.fetch_sub(1) == 1)
delete mutex;
}
}
}
-typedef struct s_smx_cond {
- s_smx_cond() : cond_(this) {}
+struct s_smx_cond_t {
+ s_smx_cond_t() : cond_(this) {}
std::atomic_int_fast32_t refcount_{1};
smx_mutex_t mutex = nullptr;
- xbt_swag_t sleeping = nullptr; /* list of sleeping process */
+ simgrid::simix::SynchroList sleeping; /* list of sleeping processes */
simgrid::s4u::ConditionVariable cond_;
-} s_smx_cond_t;
+};
-typedef struct s_smx_sem {
+struct s_smx_sem_t {
unsigned int value;
- xbt_swag_t sleeping; /* list of sleeping process */
-} s_smx_sem_t;
+ simgrid::simix::SynchroList sleeping; /* list of sleeping processes */
+};
XBT_PRIVATE void SIMIX_post_synchro(smx_activity_t synchro);
XBT_PRIVATE void SIMIX_synchro_stop_waiting(smx_actor_t process, smx_simcall_t simcall);