namespace kernel {
namespace activity {
-ConditionVariableImpl::ConditionVariableImpl() : cond_(this) {}
-ConditionVariableImpl::~ConditionVariableImpl() = default;
-
/**
* @brief Signalizes a condition.
*
/* If there is a mutex unlock it */
if (mutex != nullptr) {
- xbt_assert(mutex->owner_ == issuer,
+ xbt_assert(mutex->get_owner() == issuer,
"Actor %s cannot wait on ConditionVariable %p since it does not own the provided mutex %p",
issuer->get_cname(), this, mutex);
mutex_ = mutex;
namespace activity {
class XBT_PUBLIC ConditionVariableImpl {
-public:
- ConditionVariableImpl();
- ~ConditionVariableImpl();
-
- actor::SynchroList sleeping_; /* list of sleeping processes */
MutexImpl* mutex_ = nullptr;
- s4u::ConditionVariable cond_;
-
- void broadcast();
- void signal();
- void wait(MutexImpl* mutex, double timeout, actor::ActorImpl* issuer);
+ s4u::ConditionVariable piface_;
+ actor::SynchroList sleeping_; /* list of sleeping actors*/
-private:
std::atomic_int_fast32_t refcount_{1};
friend void intrusive_ptr_add_ref(ConditionVariableImpl* cond);
friend void intrusive_ptr_release(ConditionVariableImpl* cond);
+
+public:
+ ConditionVariableImpl() : piface_(this){};
+ ~ConditionVariableImpl() = default;
+
+ void remove_sleeping_actor(actor::ActorImpl& actor) { xbt::intrusive_erase(sleeping_, actor); }
+ s4u::ConditionVariable* get_iface() { return &piface_; }
+ void broadcast();
+ void signal();
+ void wait(MutexImpl* mutex, double timeout, actor::ActorImpl* issuer);
};
} // namespace activity
} // namespace kernel
std::atomic_int_fast32_t refcount_{1};
s4u::Mutex piface_;
bool locked_ = false;
+ actor::ActorImpl* owner_ = nullptr;
+ // List of sleeping actors:
+ actor::SynchroList sleeping_;
public:
MutexImpl() : piface_(this) {}
MutexImpl* ref();
void unref();
- actor::ActorImpl* owner_ = nullptr;
- // List of sleeping actors:
- actor::SynchroList sleeping_;
+ void remove_sleeping_actor(actor::ActorImpl& actor) { xbt::intrusive_erase(sleeping_, actor); }
+ actor::ActorImpl* get_owner() const { return owner_; }
// boost::intrusive_ptr<Mutex> support:
friend void intrusive_ptr_add_ref(MutexImpl* mutex)
class XBT_PUBLIC SemaphoreImpl {
std::atomic_int_fast32_t refcount_{1};
unsigned int value_;
-
-public:
actor::SynchroList sleeping_; /* list of sleeping actors*/
+public:
explicit SemaphoreImpl(unsigned int value) : value_(value){};
~SemaphoreImpl() = default;
void acquire(actor::ActorImpl* issuer, double timeout);
void release();
bool would_block() { return (value_ == 0); }
+ void remove_sleeping_actor(actor::ActorImpl& actor) { xbt::intrusive_erase(sleeping_, actor); }
unsigned int get_capacity() { return value_; }
+ bool is_used() { return not sleeping_.empty(); }
friend void intrusive_ptr_add_ref(SemaphoreImpl* sem)
{
switch (simcall->call_) {
case SIMCALL_MUTEX_LOCK:
- xbt::intrusive_erase(simcall_mutex_lock__get__mutex(simcall)->sleeping_, *simcall->issuer_);
+ simcall_mutex_lock__get__mutex(simcall)->remove_sleeping_actor(*simcall->issuer_);
break;
case SIMCALL_COND_WAIT:
- xbt::intrusive_erase(simcall_cond_wait__get__cond(simcall)->sleeping_, *simcall->issuer_);
+ simcall_cond_wait_timeout__get__cond(simcall)->remove_sleeping_actor(*simcall->issuer_);
break;
case SIMCALL_COND_WAIT_TIMEOUT:
- xbt::intrusive_erase(simcall_cond_wait_timeout__get__cond(simcall)->sleeping_, *simcall->issuer_);
+ simcall_cond_wait_timeout__get__cond(simcall)->remove_sleeping_actor(*simcall->issuer_);
simcall_cond_wait_timeout__set__result(simcall, 1); // signal a timeout
break;
case SIMCALL_SEM_ACQUIRE:
- xbt::intrusive_erase(simcall_sem_acquire__get__sem(simcall)->sleeping_, *simcall->issuer_);
+ simcall_sem_acquire_timeout__get__sem(simcall)->remove_sleeping_actor(*simcall->issuer_);
break;
case SIMCALL_SEM_ACQUIRE_TIMEOUT:
- xbt::intrusive_erase(simcall_sem_acquire_timeout__get__sem(simcall)->sleeping_, *simcall->issuer_);
+ simcall_sem_acquire_timeout__get__sem(simcall)->remove_sleeping_actor(*simcall->issuer_);
simcall_sem_acquire_timeout__set__result(simcall, 1); // signal a timeout
break;
case SIMCALL_MUTEX_LOCK: {
const kernel::activity::MutexImpl* mutex = simcall_mutex_lock__get__mutex(req);
- if (mutex->owner_ == nullptr)
+ if (mutex->get_owner() == nullptr)
return true;
- return mutex->owner_->get_pid() == req->issuer_->get_pid();
+ return mutex->get_owner()->get_pid() == req->issuer_->get_pid();
}
case SIMCALL_SEM_ACQUIRE: {
? simcall_mutex_lock__get__mutex(req)
: simcall_mutex_trylock__get__mutex(req)));
args = bprintf("locked = %d, owner = %d, sleeping = n/a", mutex.get_buffer()->is_locked(),
- mutex.get_buffer()->owner_ != nullptr
+ mutex.get_buffer()->get_owner() != nullptr
? (int)mc_model_checker->process()
- .resolve_actor(simgrid::mc::remote(mutex.get_buffer()->owner_))
+ .resolve_actor(simgrid::mc::remote(mutex.get_buffer()->get_owner()))
->get_pid()
: -1);
break;
{
kernel::activity::ConditionVariableImpl* cond =
kernel::actor::simcall([] { return new kernel::activity::ConditionVariableImpl(); });
- return ConditionVariablePtr(&cond->cond_, false);
+ return ConditionVariablePtr(cond->get_iface(), false);
}
/**
Semaphore::~Semaphore()
{
if (sem_ != nullptr) {
- xbt_assert(sem_->sleeping_.empty(), "Cannot destroy semaphore since someone is still using it");
+ xbt_assert(not sem_->is_used(), "Cannot destroy semaphore since someone is still using it");
delete sem_;
}
}
void xbt_cond_signal(xbt_cond_t cond)
{
- cond->cond_.notify_one();
+ cond->get_iface()->notify_one();
}
void xbt_cond_broadcast(xbt_cond_t cond)
{
- cond->cond_.notify_all();
+ cond->get_iface()->notify_all();
}
void xbt_cond_destroy(xbt_cond_t cond)