/************************** Synchro simcalls **********************************/
SG_BEGIN_DECL
XBT_ATTRIB_DEPRECATED_v330("Please use sg_mutex_init()") XBT_PUBLIC smx_mutex_t simcall_mutex_init();
-XBT_PUBLIC void simcall_mutex_lock(smx_mutex_t mutex);
+XBT_ATTRIB_DEPRECATED_v331("Please use sg_mutex_lock()") XBT_PUBLIC void simcall_mutex_lock(smx_mutex_t mutex);
XBT_ATTRIB_DEPRECATED_v331("Please use sg_mutex_try_lock()") XBT_PUBLIC int simcall_mutex_trylock(smx_mutex_t mutex);
XBT_ATTRIB_DEPRECATED_v331("Please use sg_mutex_unlock()") XBT_PUBLIC void simcall_mutex_unlock(smx_mutex_t mutex);
simcall_mutex = simcall_cond_wait__get__mutex(simcall);
else
simcall_mutex = simcall_cond_wait_timeout__get__mutex(simcall);
- simcall->call_ = simix::Simcall::MUTEX_LOCK;
+ simcall->call_ = simix::Simcall::RUN_BLOCKING;
simcall_mutex->lock(simcall->issuer_);
}
} // namespace activity
} // namespace kernel
} // namespace simgrid
-
-// Simcall handlers:
-
-void simcall_HANDLER_mutex_lock(smx_simcall_t simcall, smx_mutex_t mutex)
-{
- mutex->lock(simcall->issuer_);
-}
}
break;
- case Simcall::MUTEX_LOCK: {
- type = "Mutex LOCK";
- simgrid::mc::Remote<simgrid::kernel::activity::MutexImpl> mutex;
- mc_model_checker->get_remote_simulation().read_bytes(mutex.get_buffer(), sizeof(mutex),
- remote(simcall_mutex_lock__get__mutex(req)));
- args = "locked = " + std::to_string(mutex.get_buffer()->is_locked()) + ", owner = ";
- if (mutex.get_buffer()->get_owner() != nullptr)
- args += std::to_string(mc_model_checker->get_remote_simulation()
- .resolve_actor(simgrid::mc::remote(mutex.get_buffer()->get_owner()))
- ->get_pid());
- else
- args += "-1";
- args += ", sleeping = n/a";
- break;
- }
-
default:
type = SIMIX_simcall_name(req->call_);
args = "??";
}
break;
- case Simcall::MUTEX_LOCK:
- label = "[" + get_actor_dot_label(issuer) + "] Mutex LOCK";
- break;
-
default:
THROW_UNIMPLEMENTED;
}
return SimcallObserver::dot_label() + "Mutex TRYLOCK";
}
+std::string MutexLockSimcall::to_string(int time_considered) const
+{
+ std::string res = SimcallObserver::to_string(time_considered) + "Mutex LOCK";
+ res += "(locked = " + std::to_string(mutex_->is_locked());
+ res += ", owner = " + std::to_string(mutex_->get_owner() ? mutex_->get_owner()->get_pid() : -1);
+ res += ", sleeping = n/a)";
+ return res;
+}
+
+std::string MutexLockSimcall::dot_label() const
+{
+ return SimcallObserver::dot_label() + "Mutex LOCK";
+}
+
+bool MutexLockSimcall::is_enabled() const
+{
+ return mutex_->get_owner() == nullptr || mutex_->get_owner() == get_issuer();
+}
} // namespace mc
} // namespace simgrid
std::string dot_label() const override;
kernel::activity::MutexImpl* get_mutex() const { return mutex_; }
};
+
+class MutexLockSimcall : public SimcallObserver {
+ kernel::activity::MutexImpl* mutex_;
+
+public:
+ MutexLockSimcall(smx_actor_t actor, kernel::activity::MutexImpl* mutex) : SimcallObserver(actor), mutex_(mutex) {}
+ bool is_enabled() const override;
+ std::string to_string(int times_considered) const override;
+ std::string dot_label() const override;
+ kernel::activity::MutexImpl* get_mutex() const { return mutex_; }
+};
} // namespace mc
} // namespace simgrid
return false;
}
- case Simcall::MUTEX_LOCK: {
- const kernel::activity::MutexImpl* mutex = simcall_mutex_lock__get__mutex(req);
-
- if (mutex->get_owner() == nullptr)
- return true;
- return mutex->get_owner()->get_pid() == req->issuer_->get_pid();
- }
-
case Simcall::SEM_ACQUIRE: {
static bool warned = false;
if (not warned)
using simix::Simcall;
return req->call_ == Simcall::COMM_ISEND || req->call_ == Simcall::COMM_IRECV || req->call_ == Simcall::COMM_WAIT ||
- req->call_ == Simcall::COMM_WAITANY || req->call_ == Simcall::COMM_TEST ||
- req->call_ == Simcall::COMM_TESTANY || req->call_ == Simcall::MUTEX_LOCK;
+ req->call_ == Simcall::COMM_WAITANY || req->call_ == Simcall::COMM_TEST || req->call_ == Simcall::COMM_TESTANY;
}
}
/** @brief Blocks the calling actor until the mutex can be obtained */
void Mutex::lock()
{
- simcall_mutex_lock(pimpl_);
+ kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
+ mc::MutexLockSimcall observer{issuer, pimpl_};
+ kernel::actor::simcall_blocking<void>([&observer] { observer.get_mutex()->lock(observer.get_issuer()); }, &observer);
}
/** @brief Release the ownership of the mutex, unleashing a blocked actor (if any)
* @ingroup simix_synchro_management
*
*/
-void simcall_mutex_lock(smx_mutex_t mutex)
+void simcall_mutex_lock(smx_mutex_t mutex) // XBT_ATTRIB_DEPRECATD_v331
{
- simcall_BODY_mutex_lock(mutex);
+ mutex->mutex().lock();
}
/**
simgrid::simix::marshal<int>(simcall->result_, result);
}
-static inline smx_mutex_t simcall_mutex_lock__get__mutex(smx_simcall_t simcall)
-{
- return simgrid::simix::unmarshal<smx_mutex_t>(simcall->args_[0]);
-}
-static inline smx_mutex_t simcall_mutex_lock__getraw__mutex(smx_simcall_t simcall)
-{
- return simgrid::simix::unmarshal_raw<smx_mutex_t>(simcall->args_[0]);
-}
-static inline void simcall_mutex_lock__set__mutex(smx_simcall_t simcall, smx_mutex_t arg)
-{
- simgrid::simix::marshal<smx_mutex_t>(simcall->args_[0], arg);
-}
-
static inline smx_cond_t simcall_cond_wait__get__cond(smx_simcall_t simcall)
{
return simgrid::simix::unmarshal<smx_cond_t>(simcall->args_[0]);
XBT_PRIVATE void simcall_HANDLER_comm_wait(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl* comm, double timeout);
XBT_PRIVATE void simcall_HANDLER_comm_test(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl* comm);
XBT_PRIVATE void simcall_HANDLER_comm_testany(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl** comms, size_t count);
-XBT_PRIVATE void simcall_HANDLER_mutex_lock(smx_simcall_t simcall, smx_mutex_t mutex);
XBT_PRIVATE void simcall_HANDLER_cond_wait(smx_simcall_t simcall, smx_cond_t cond, smx_mutex_t mutex);
XBT_PRIVATE void simcall_HANDLER_cond_wait_timeout(smx_simcall_t simcall, smx_cond_t cond, smx_mutex_t mutex, double timeout);
XBT_PRIVATE void simcall_HANDLER_sem_acquire(smx_simcall_t simcall, smx_sem_t sem);
return simcall<int, simgrid::kernel::activity::CommImpl**, size_t>(Simcall::COMM_TESTANY, comms, count);
}
-inline static void simcall_BODY_mutex_lock(smx_mutex_t mutex)
-{
- if (false) /* Go to that function to follow the code flow through the simcall barrier */
- simcall_HANDLER_mutex_lock(&SIMIX_process_self()->simcall_, mutex);
- return simcall<void, smx_mutex_t>(Simcall::MUTEX_LOCK, mutex);
-}
-
inline static void simcall_BODY_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
{
if (false) /* Go to that function to follow the code flow through the simcall barrier */
COMM_WAIT,
COMM_TEST,
COMM_TESTANY,
- MUTEX_LOCK,
COND_WAIT,
COND_WAIT_TIMEOUT,
SEM_ACQUIRE,
RUN_BLOCKING,
};
-constexpr int NUM_SIMCALLS = 17;
+constexpr int NUM_SIMCALLS = 16;
} // namespace simix
} // namespace simgrid
"Simcall::COMM_WAIT",
"Simcall::COMM_TEST",
"Simcall::COMM_TESTANY",
- "Simcall::MUTEX_LOCK",
"Simcall::COND_WAIT",
"Simcall::COND_WAIT_TIMEOUT",
"Simcall::SEM_ACQUIRE",
simcall_HANDLER_comm_testany(&simcall_, simgrid::simix::unmarshal<simgrid::kernel::activity::CommImpl**>(simcall_.args_[0]), simgrid::simix::unmarshal<size_t>(simcall_.args_[1]));
break;
- case Simcall::MUTEX_LOCK:
- simcall_HANDLER_mutex_lock(&simcall_, simgrid::simix::unmarshal<smx_mutex_t>(simcall_.args_[0]));
- break;
-
case Simcall::COND_WAIT:
simcall_HANDLER_cond_wait(&simcall_, simgrid::simix::unmarshal<smx_cond_t>(simcall_.args_[0]), simgrid::simix::unmarshal<smx_mutex_t>(simcall_.args_[1]));
break;
bool comm_test(simgrid::kernel::activity::CommImpl* comm) [[block]];
int comm_testany(simgrid::kernel::activity::CommImpl** comms, size_t count) [[block]];
-void mutex_lock(smx_mutex_t mutex) [[block]];
-
void cond_wait(smx_cond_t cond, smx_mutex_t mutex) [[block]];
int cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, double timeout) [[block]];