#include "simgrid/s4u/Activity.hpp"
XBT_LOG_EXTERNAL_CATEGORY(s4u);
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_activity,s4u,"S4U activities");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_activity, s4u, "S4U activities");
namespace simgrid {
namespace s4u {
return this;
}
-}
-}
+} // namespace s4u
+} // namespace simgrid
ActorPtr Actor::create(const char* name, s4u::Host* host, const char* function, std::vector<std::string> args)
{
simgrid::simix::ActorCodeFactory& factory = SIMIX_get_actor_code_factory(function);
- simgrid::simix::ActorCode code = factory(std::move(args));
+ simgrid::simix::ActorCode code = factory(std::move(args));
simgrid::kernel::actor::ActorImpl* actor = simcall_process_create(name, std::move(code), nullptr, host, nullptr);
return actor->iface();
}
// ***** Actor methods *****
-void Actor::join() {
+void Actor::join()
+{
simcall_process_join(this->pimpl_, -1);
}
void Actor::set_kill_time(double time)
{
- simcall_process_set_kill_time(pimpl_,time);
+ simcall_process_set_kill_time(pimpl_, time);
}
/** \brief Get the kill time of an actor(or 0 if unset). */
{
smx_actor_t killer = SIMIX_process_self();
smx_actor_t process = SIMIX_process_from_PID(pid);
- if(process != nullptr) {
+ if (process != nullptr) {
simgrid::simix::kernelImmediate([killer, process] { SIMIX_process_kill(process, killer); });
} else {
std::ostringstream oss;
}
}
-void Actor::kill() {
+void Actor::kill()
+{
smx_actor_t process = SIMIX_process_self();
simgrid::simix::kernelImmediate(
[this, process] { SIMIX_process_kill(pimpl_, (pimpl_ == simix_global->maestro_process) ? pimpl_ : process); });
xbt_dict_t sg_actor_get_properties(sg_actor_t actor)
{
xbt_assert(actor != nullptr, "Invalid parameter: First argument must not be nullptr");
- xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
+ xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
std::map<std::string, std::string>* props = actor->get_properties();
if (props == nullptr)
return nullptr;
}
/** \ingroup m_actor_management
-* \brief Wait for the completion of a #sg_actor_t.
-*
-* \param actor the actor to wait for
-* \param timeout wait until the actor is over, or the timeout expires
-*/
+ * \brief Wait for the completion of a #sg_actor_t.
+ *
+ * \param actor the actor to wait for
+ * \param timeout wait until the actor is over, or the timeout expires
+ */
void sg_actor_join(sg_actor_t actor, double timeout)
{
actor->join(timeout);
#include "simgrid/s4u/Comm.hpp"
#include "simgrid/s4u/Mailbox.hpp"
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_comm,s4u_activity,"S4U asynchronous communications");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_comm, s4u_activity, "S4U asynchronous communications");
namespace simgrid {
namespace s4u {
if (state_ == State::inited)
this->start();
- if(simcall_comm_test(pimpl_)){
+ if (simcall_comm_test(pimpl_)) {
state_ = State::finished;
return true;
}
{
c->refcount_.fetch_add(1, std::memory_order_relaxed);
}
-}
-} // namespaces
+} // namespace s4u
+} // namespace simgrid
simcall_cond_wait(cond_, lock->mutex_);
}
-void ConditionVariable::wait(std::unique_lock<Mutex>& lock) {
+void ConditionVariable::wait(std::unique_lock<Mutex>& lock)
+{
simcall_cond_wait(cond_, lock.mutex()->mutex_);
}
-std::cv_status s4u::ConditionVariable::wait_for(std::unique_lock<Mutex>& lock, double timeout) {
+std::cv_status s4u::ConditionVariable::wait_for(std::unique_lock<Mutex>& lock, double timeout)
+{
// The simcall uses -1 for "any timeout" but we don't want this:
if (timeout < 0)
timeout = 0.0;
try {
simcall_cond_wait_timeout(cond_, lock.mutex()->mutex_, timeout);
return std::cv_status::no_timeout;
- }
- catch (xbt_ex& e) {
+ } catch (xbt_ex& e) {
// If the exception was a timeout, we have to take the lock again:
if (e.category == timeout_error) {
try {
lock.mutex()->lock();
return std::cv_status::timeout;
- }
- catch (...) {
+ } catch (...) {
std::terminate();
}
}
// Another exception: should we reaquire the lock?
std::terminate();
- }
- catch (...) {
+ } catch (...) {
std::terminate();
}
}
/**
* Notify functions
*/
-void ConditionVariable::notify_one() {
+void ConditionVariable::notify_one()
+{
simgrid::simix::kernelImmediate([this]() { cond_->signal(); });
}
-void ConditionVariable::notify_all() {
+void ConditionVariable::notify_all()
+{
simgrid::simix::kernelImmediate([this]() { cond_->broadcast(); });
}
intrusive_ptr_release(cond->cond_);
}
-}
-}
+} // namespace s4u
+} // namespace simgrid
#include "src/surf/network_interface.hpp"
#include "surf/surf.hpp" // routing_platf. FIXME:KILLME. SOON
-XBT_LOG_NEW_CATEGORY(s4u,"Log channels of the S4U (Simgrid for you) interface");
+XBT_LOG_NEW_CATEGORY(s4u, "Log channels of the S4U (Simgrid for you) interface");
namespace simgrid {
namespace s4u {
xbt::signal<void(double)> onTimeAdvance;
xbt::signal<void(void)> onDeadlock;
-Engine *Engine::instance_ = nullptr; /* That singleton is awful, but I don't see no other solution right now. */
+Engine* Engine::instance_ = nullptr; /* That singleton is awful, but I don't see no other solution right now. */
-Engine::Engine(int *argc, char **argv) {
- xbt_assert(s4u::Engine::instance_ == nullptr, "It is currently forbidden to create more than one instance of s4u::Engine");
+Engine::Engine(int* argc, char** argv)
+{
+ xbt_assert(s4u::Engine::instance_ == nullptr,
+ "It is currently forbidden to create more than one instance of s4u::Engine");
TRACE_global_init();
SIMIX_global_init(argc, argv);
return s4u::Engine::instance_;
}
-void Engine::shutdown() {
+void Engine::shutdown()
+{
delete s4u::Engine::instance_;
s4u::Engine::instance_ = nullptr;
}
return SIMIX_get_clock();
}
-void Engine::loadPlatform(const char *platf)
+void Engine::loadPlatform(const char* platf)
{
SIMIX_create_environment(platf);
}
-void Engine::registerFunction(const char*name, int (*code)(int,char**))
+void Engine::registerFunction(const char* name, int (*code)(int, char**))
{
- SIMIX_function_register(name,code);
+ SIMIX_function_register(name, code);
}
-void Engine::registerDefault(int (*code)(int,char**))
+void Engine::registerDefault(int (*code)(int, char**))
{
SIMIX_function_register_default(code);
}
-void Engine::loadDeployment(const char *deploy)
+void Engine::loadDeployment(const char* deploy)
{
SIMIX_launch_application(deploy);
}
/** @brief Fills the passed list with all hosts found in the platform
* @deprecated Please prefer Engine::getAllHosts()
*/
-void XBT_ATTRIB_DEPRECATED_v322("Engine::getHostList() is deprecated in favor of Engine::getAllHosts(). Please switch before v3.22")
-Engine::getHostList(std::vector<Host*>* list)
+void XBT_ATTRIB_DEPRECATED_v322(
+ "Engine::getHostList() is deprecated in favor of Engine::getAllHosts(). Please switch before v3.22")
+ Engine::getHostList(std::vector<Host*>* list)
{
for (auto const& kv : pimpl->hosts_)
list->push_back(kv.second);
/** @brief Fills the passed list with all links found in the platform
*
* @deprecated. Prefer Engine::getAllLinks() */
-void XBT_ATTRIB_DEPRECATED_v322("Engine::getLinkList() is deprecated in favor of Engine::getAllLinks(). Please switch before v3.22")
-Engine::getLinkList(std::vector<Link*>* list)
+void XBT_ATTRIB_DEPRECATED_v322(
+ "Engine::getLinkList() is deprecated in favor of Engine::getAllLinks(). Please switch before v3.22")
+ Engine::getLinkList(std::vector<Link*>* list)
{
kernel::resource::LinkImpl::linksList(list);
}
return res;
}
-void Engine::run() {
+void Engine::run()
+{
if (MC_is_active()) {
MC_run();
} else {
{
simgrid::config::set_parse(std::move(str));
}
-}
-} // namespace
+} // namespace s4u
+} // namespace simgrid
{
e->refcount_.fetch_add(1, std::memory_order_relaxed);
}
-}
-}
+} // namespace s4u
+} // namespace simgrid
simgrid::xbt::signal<void(Host&)> Host::onStateChange;
simgrid::xbt::signal<void(Host&)> Host::onSpeedChange;
-Host::Host(const char* name)
- : name_(name)
+Host::Host(const char* name) : name_(name)
{
xbt_assert(Host::by_name_or_null(name) == nullptr, "Refusing to create a second host named '%s'.", name);
Engine::getInstance()->addHost(std::string(name_), this);
return Engine::getInstance()->hostByNameOrNull(name);
}
-Host *Host::current(){
+Host* Host::current()
+{
smx_actor_t smx_proc = SIMIX_process_self();
if (smx_proc == nullptr)
xbt_die("Cannot call Host::current() from the maestro context");
return smx_proc->host;
}
-void Host::turnOn() {
+void Host::turnOn()
+{
if (isOff()) {
simgrid::simix::kernelImmediate([this] {
this->extension<simgrid::simix::Host>()->turnOn();
}
}
-void Host::turnOff() {
+void Host::turnOff()
+{
if (isOn()) {
smx_actor_t self = SIMIX_process_self();
simgrid::simix::kernelImmediate([this, self] {
}
}
-bool Host::isOn() {
+bool Host::isOn()
+{
return this->pimpl_cpu->is_on();
}
/** @brief Get the peak processor speed (in flops/s), at the specified pstate */
double Host::getPstateSpeed(int pstate_index)
{
- return simgrid::simix::kernelImmediate([this, pstate_index] {
- return this->pimpl_cpu->getPstateSpeed(pstate_index);
- });
+ return simgrid::simix::kernelImmediate(
+ [this, pstate_index] { return this->pimpl_cpu->getPstateSpeed(pstate_index); });
}
/** @brief Get the peak processor speed (under full load (=1.0), in flops/s), at the current pstate */
/** @brief Set the pstate at which the host should run */
void Host::setPstate(int pstate_index)
{
- simgrid::simix::kernelImmediate([this, pstate_index] {
- this->pimpl_cpu->setPState(pstate_index);
- });
+ simgrid::simix::kernelImmediate([this, pstate_index] { this->pimpl_cpu->setPState(pstate_index); });
}
/** @brief Retrieve the pstate at which the host is currently running */
int Host::getPstate()
return this->pimpl_cpu->get_load();
}
-} // namespace simgrid
} // namespace s4u
+} // namespace simgrid
sg_link_t* sg_link_list()
{
simgrid::kernel::resource::LinkImpl** list = simgrid::kernel::resource::LinkImpl::linksList();
- sg_link_t* res = (sg_link_t*)list; // Use the same memory area
+ sg_link_t* res = (sg_link_t*)list; // Use the same memory area
int size = sg_link_count();
for (int i = 0; i < size; i++)
}
void Link::setData(void* d)
{
- simgrid::simix::kernelImmediate([this, d]() {
- this->pimpl_->setData(d);
- });
+ simgrid::simix::kernelImmediate([this, d]() { this->pimpl_->setData(d); });
}
void Link::setStateTrace(tmgr_trace_t trace)
{
- simgrid::simix::kernelImmediate([this, trace]() {
- this->pimpl_->setStateTrace(trace);
- });
+ simgrid::simix::kernelImmediate([this, trace]() { this->pimpl_->setStateTrace(trace); });
}
void Link::setBandwidthTrace(tmgr_trace_t trace)
{
- simgrid::simix::kernelImmediate([this, trace]() {
- this->pimpl_->setBandwidthTrace(trace);
- });
+ simgrid::simix::kernelImmediate([this, trace]() { this->pimpl_->setBandwidthTrace(trace); });
}
void Link::setLatencyTrace(tmgr_trace_t trace)
{
- simgrid::simix::kernelImmediate([this, trace]() {
- this->pimpl_->setLatencyTrace(trace);
- });
+ simgrid::simix::kernelImmediate([this, trace]() { this->pimpl_->setLatencyTrace(trace); });
}
const char* Link::getProperty(const char* key)
simgrid::xbt::signal<void(s4u::Link&)> Link::onStateChange;
simgrid::xbt::signal<void(kernel::resource::NetworkAction*, s4u::Host* src, s4u::Host* dst)> Link::onCommunicate;
simgrid::xbt::signal<void(kernel::resource::NetworkAction*)> Link::onCommunicationStateChange;
-}
-}
+} // namespace s4u
+} // namespace simgrid
#include "xbt/log.h"
XBT_LOG_EXTERNAL_CATEGORY(s4u);
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_channel,s4u,"S4U Communication Mailboxes");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_channel, s4u, "S4U Communication Mailboxes");
namespace simgrid {
namespace s4u {
return pimpl_->get_cname();
}
-MailboxPtr Mailbox::byName(const char*name)
+MailboxPtr Mailbox::byName(const char* name)
{
kernel::activity::MailboxImpl* mbox = kernel::activity::MailboxImpl::byNameOrNull(name);
if (mbox == nullptr) {
- mbox = simix::kernelImmediate([name] {
- return kernel::activity::MailboxImpl::byNameOrCreate(name);
- });
+ mbox = simix::kernelImmediate([name] { return kernel::activity::MailboxImpl::byNameOrCreate(name); });
}
return MailboxPtr(&mbox->piface_, true);
}
return pimpl_->comm_queue.empty() ? nullptr : pimpl_->comm_queue.front();
}
-void Mailbox::setReceiver(ActorPtr actor) {
+void Mailbox::setReceiver(ActorPtr actor)
+{
simix::kernelImmediate([this, actor]() { this->pimpl_->setReceiver(actor); });
}
c->wait(timeout);
return res;
}
-}
-}
+} // namespace s4u
+} // namespace simgrid
xbt_assert(mutex);
SIMIX_mutex_unref(mutex->mutex_);
}
-}
-}
+} // namespace s4u
+} // namespace simgrid
std::unordered_map<std::string, std::string>* NetZone::getProperties()
{
- return simgrid::simix::kernelImmediate([this] {
- return &properties_;
- });
+ return simgrid::simix::kernelImmediate([this] { return &properties_; });
}
/** Retrieve the property value (or nullptr if not set) */
}
void NetZone::setProperty(const char* key, const char* value)
{
- simgrid::simix::kernelImmediate([this,key,value] {
- properties_[key] = value;
- });
+ simgrid::simix::kernelImmediate([this, key, value] { properties_[key] = value; });
}
/** @brief Returns the list of direct children (no grand-children)
xbt_dict_t sg_storage_get_properties(sg_storage_t storage)
{
xbt_assert((storage != nullptr), "Invalid parameters (storage is nullptr)");
- xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
+ xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
std::map<std::string, std::string>* props = storage->getProperties();
if (props == nullptr)
return nullptr;
xbt_dynar_t sg_storages_as_dynar()
{
std::vector<simgrid::s4u::Storage*> storage_list = simgrid::s4u::Engine::getInstance()->getAllStorages();
- xbt_dynar_t res = xbt_dynar_new(sizeof(sg_storage_t), nullptr);
+ xbt_dynar_t res = xbt_dynar_new(sizeof(sg_storage_t), nullptr);
for (auto const& s : storage_list)
xbt_dynar_push(res, &s);
return res;
endif()
set(S4U_SRC
- src/s4u/s4u_actor.cpp
- src/s4u/s4u_activity.cpp
- src/s4u/s4u_conditionVariable.cpp
- src/s4u/s4u_comm.cpp
- src/s4u/s4u_engine.cpp
- src/s4u/s4u_exec.cpp
- src/s4u/s4u_host.cpp
- src/s4u/s4u_link.cpp
- src/s4u/s4u_mailbox.cpp
- src/s4u/s4u_mutex.cpp
- src/s4u/s4u_netzone.cpp
- src/s4u/s4u_storage.cpp
+ src/s4u/s4u_Actor.cpp
+ src/s4u/s4u_Activity.cpp
+ src/s4u/s4u_ConditionVariable.cpp
+ src/s4u/s4u_Comm.cpp
+ src/s4u/s4u_Engine.cpp
+ src/s4u/s4u_Exec.cpp
+ src/s4u/s4u_Host.cpp
+ src/s4u/s4u_Link.cpp
+ src/s4u/s4u_Mailbox.cpp
+ src/s4u/s4u_Mutex.cpp
+ src/s4u/s4u_Netzone.cpp
+ src/s4u/s4u_Storage.cpp
)
set(SIMGRID_SRC