const char* what() const noexcept { return msg_.c_str(); }
static void do_throw();
- static bool try_n_catch(std::function<void(void)> try_block);
+ static bool try_n_catch(const std::function<void()>& try_block);
private:
std::string msg_ = std::string("Actor killed.");
JavaContextFactory::~JavaContextFactory()=default;
-JavaContext* JavaContextFactory::create_context(std::function<void()> code, smx_actor_t actor)
+JavaContext* JavaContextFactory::create_context(std::function<void()>&& code, smx_actor_t actor)
{
return this->new_context<JavaContext>(std::move(code), actor);
}
SerialThreadContext::run_all();
}
-JavaContext::JavaContext(std::function<void()> code, smx_actor_t actor)
+JavaContext::JavaContext(std::function<void()>&& code, smx_actor_t actor)
: SerialThreadContext(std::move(code), actor, false /* not maestro */)
{
/* ThreadContext already does all we need */
JNIEnv* jenv_ = nullptr;
friend class JavaContextFactory;
- JavaContext(std::function<void()> code, smx_actor_t actor);
+ JavaContext(std::function<void()>&& code, smx_actor_t actor);
void start_hook() override;
void stop_hook() override;
public:
JavaContextFactory();
~JavaContextFactory() override;
- JavaContext* create_context(std::function<void()> code, smx_actor_t actor) override;
+ JavaContext* create_context(std::function<void()>&& code, smx_actor_t actor) override;
void run_all() override;
};
"Try using --cfg=contexts/factory:thread instead.\n");
}
-Context* ContextFactory::create_maestro(std::function<void()>, smx_actor_t)
+Context* ContextFactory::create_maestro(std::function<void()>&&, smx_actor_t)
{
xbt_die("Cannot create_maestro with this ContextFactory.\n"
"Try using --cfg=contexts/factory:thread instead.\n");
}
-Context::Context(std::function<void()> code, smx_actor_t actor) : code_(std::move(code)), actor_(actor)
+Context::Context(std::function<void()>&& code, smx_actor_t actor) : code_(std::move(code)), actor_(actor)
{
/* If no function was provided, this is the context for maestro
* and we should set it as the current context */
ContextFactory(const ContextFactory&) = delete;
ContextFactory& operator=(const ContextFactory&) = delete;
virtual ~ContextFactory();
- virtual Context* create_context(std::function<void()> code, smx_actor_t actor) = 0;
+ virtual Context* create_context(std::function<void()>&& code, smx_actor_t actor) = 0;
/** Turn the current thread into a simulation context */
virtual Context* attach(smx_actor_t actor);
/** Turn the current thread into maestro (the old maestro becomes a regular actor) */
- virtual Context* create_maestro(std::function<void()> code, smx_actor_t actor);
+ virtual Context* create_maestro(std::function<void()>&& code, smx_actor_t actor);
virtual void run_all() = 0;
public:
bool iwannadie = false;
- Context(std::function<void()> code, smx_actor_t actor);
+ Context(std::function<void()>&& code, smx_actor_t actor);
Context(const Context&) = delete;
Context& operator=(const Context&) = delete;
virtual ~Context();
class XBT_PUBLIC AttachContext : public Context {
public:
- AttachContext(std::function<void()> code, smx_actor_t actor) : Context(std::move(code), actor) {}
+ AttachContext(std::function<void()>&& code, smx_actor_t actor) : Context(std::move(code), actor) {}
AttachContext(const AttachContext&) = delete;
AttachContext& operator=(const AttachContext&) = delete;
~AttachContext() override;
namespace context {
// BoostContextFactory
-smx_context_t BoostContextFactory::create_context(std::function<void()> code, smx_actor_t actor)
+smx_context_t BoostContextFactory::create_context(std::function<void()>&& code, smx_actor_t actor)
{
return this->new_context<BoostContext>(std::move(code), actor, this);
}
// BoostContext
-BoostContext::BoostContext(std::function<void()> code, smx_actor_t actor, SwappedContextFactory* factory)
+BoostContext::BoostContext(std::function<void()>&& code, smx_actor_t actor, SwappedContextFactory* factory)
: SwappedContext(std::move(code), actor, factory)
{
/** @brief Userspace context switching implementation based on Boost.Context */
class BoostContext : public SwappedContext {
public:
- BoostContext(std::function<void()> code, smx_actor_t actor, SwappedContextFactory* factory);
+ BoostContext(std::function<void()>&& code, smx_actor_t actor, SwappedContextFactory* factory);
~BoostContext() override;
void swap_into(SwappedContext* to) override;
class BoostContextFactory : public SwappedContextFactory {
public:
- Context* create_context(std::function<void()> code, smx_actor_t actor) override;
+ Context* create_context(std::function<void()>&& code, smx_actor_t actor) override;
};
}}} // namespace
// RawContextFactory
-Context* RawContextFactory::create_context(std::function<void()> code, smx_actor_t actor)
+Context* RawContextFactory::create_context(std::function<void()>&& code, smx_actor_t actor)
{
return this->new_context<RawContext>(std::move(code), actor, this);
}
// RawContext
-RawContext::RawContext(std::function<void()> code, smx_actor_t actor, SwappedContextFactory* factory)
+RawContext::RawContext(std::function<void()>&& code, smx_actor_t actor, SwappedContextFactory* factory)
: SwappedContext(std::move(code), actor, factory)
{
if (has_code()) {
*/
class RawContext : public SwappedContext {
public:
- RawContext(std::function<void()> code, smx_actor_t actor, SwappedContextFactory* factory);
+ RawContext(std::function<void()>&& code, smx_actor_t actor, SwappedContextFactory* factory);
void swap_into(SwappedContext* to) override;
class RawContextFactory : public SwappedContextFactory {
public:
- Context* create_context(std::function<void()> code, smx_actor_t actor) override;
+ Context* create_context(std::function<void()>&& code, smx_actor_t actor) override;
};
}}} // namespace
delete parmap_;
}
-SwappedContext::SwappedContext(std::function<void()> code, smx_actor_t actor, SwappedContextFactory* factory)
+SwappedContext::SwappedContext(std::function<void()>&& code, smx_actor_t actor, SwappedContextFactory* factory)
: Context(std::move(code), actor), factory_(factory)
{
// Save maestro (=context created first) in preparation for run_all
class SwappedContext : public Context {
public:
- SwappedContext(std::function<void()> code, smx_actor_t get_actor, SwappedContextFactory* factory);
+ SwappedContext(std::function<void()>&& code, smx_actor_t get_actor, SwappedContextFactory* factory);
SwappedContext(const SwappedContext&) = delete;
SwappedContext& operator=(const SwappedContext&) = delete;
virtual ~SwappedContext();
ParallelThreadContext::finalize();
}
-ThreadContext* ThreadContextFactory::create_context(std::function<void()> code, smx_actor_t actor, bool maestro)
+ThreadContext* ThreadContextFactory::create_context(std::function<void()>&& code, smx_actor_t actor, bool maestro)
{
if (parallel_)
return this->new_context<ParallelThreadContext>(std::move(code), actor, maestro);
// ThreadContext
-ThreadContext::ThreadContext(std::function<void()> code, smx_actor_t actor, bool maestro)
+ThreadContext::ThreadContext(std::function<void()>&& code, smx_actor_t actor, bool maestro)
: AttachContext(std::move(code), actor), is_maestro_(maestro)
{
/* If the user provided a function for the actor then use it */
class XBT_PUBLIC ThreadContext : public AttachContext {
public:
- ThreadContext(std::function<void()> code, smx_actor_t actor, bool maestro);
+ ThreadContext(std::function<void()>&& code, smx_actor_t actor, bool maestro);
ThreadContext(const ThreadContext&) = delete;
ThreadContext& operator=(const ThreadContext&) = delete;
~ThreadContext() override;
class XBT_PUBLIC SerialThreadContext : public ThreadContext {
public:
- SerialThreadContext(std::function<void()> code, smx_actor_t actor, bool maestro)
+ SerialThreadContext(std::function<void()>&& code, smx_actor_t actor, bool maestro)
: ThreadContext(std::move(code), actor, maestro)
{
}
class ParallelThreadContext : public ThreadContext {
public:
- ParallelThreadContext(std::function<void()> code, smx_actor_t actor, bool maestro)
+ ParallelThreadContext(std::function<void()>&& code, smx_actor_t actor, bool maestro)
: ThreadContext(std::move(code), actor, maestro)
{
}
ThreadContextFactory(const ThreadContextFactory&) = delete;
ThreadContextFactory& operator=(const ThreadContextFactory&) = delete;
~ThreadContextFactory() override;
- ThreadContext* create_context(std::function<void()> code, smx_actor_t actor) override
+ ThreadContext* create_context(std::function<void()>&& code, smx_actor_t actor) override
{
bool maestro = not code;
return create_context(std::move(code), actor, maestro);
// Optional methods:
ThreadContext* attach(smx_actor_t actor) override { return create_context(std::function<void()>(), actor, false); }
- ThreadContext* create_maestro(std::function<void()> code, smx_actor_t actor) override
+ ThreadContext* create_maestro(std::function<void()>&& code, smx_actor_t actor) override
{
return create_context(std::move(code), actor, true);
}
private:
bool parallel_;
- ThreadContext* create_context(std::function<void()> code, smx_actor_t actor, bool maestro);
+ ThreadContext* create_context(std::function<void()>&& code, smx_actor_t actor, bool maestro);
};
}}} // namespace
namespace context {
// UContextFactory
-Context* UContextFactory::create_context(std::function<void()> code, smx_actor_t actor)
+Context* UContextFactory::create_context(std::function<void()>&& code, smx_actor_t actor)
{
return new_context<UContext>(std::move(code), actor, this);
}
// UContext
-UContext::UContext(std::function<void()> code, smx_actor_t actor, SwappedContextFactory* factory)
+UContext::UContext(std::function<void()>&& code, smx_actor_t actor, SwappedContextFactory* factory)
: SwappedContext(std::move(code), actor, factory)
{
/* if the user provided a function for the actor then use it. If not, nothing to do for maestro. */
class UContext : public SwappedContext {
public:
- UContext(std::function<void()> code, smx_actor_t actor, SwappedContextFactory* factory);
+ UContext(std::function<void()>&& code, smx_actor_t actor, SwappedContextFactory* factory);
void swap_into(SwappedContext* to) override;
class UContextFactory : public SwappedContextFactory {
public:
- Context* create_context(std::function<void()> code, smx_actor_t actor) override;
+ Context* create_context(std::function<void()>&& code, smx_actor_t actor) override;
};
}}} // namespace
throw ForcefulKillException();
}
-bool ForcefulKillException::try_n_catch(std::function<void(void)> try_block)
+bool ForcefulKillException::try_n_catch(const std::function<void()>& try_block)
{
bool res;
try {
return ActorImplPtr(actor);
}
-ActorImpl* ActorImpl::start(simix::ActorCode code)
+ActorImpl* ActorImpl::start(const simix::ActorCode& code)
{
xbt_assert(code && host_ != nullptr, "Invalid parameters");
this->code = code;
XBT_VERB("Create context %s", get_cname());
- context_ = simix_global->context_factory->create_context(std::move(code), this);
+ context_ = simix_global->context_factory->create_context(simix::ActorCode(code), this);
XBT_DEBUG("Start context '%s'", get_cname());
return this;
}
-ActorImplPtr ActorImpl::create(std::string name, simix::ActorCode code, void* data, s4u::Host* host,
+ActorImplPtr ActorImpl::create(std::string name, const simix::ActorCode& code, void* data, s4u::Host* host,
std::unordered_map<std::string, std::string>* properties, ActorImpl* parent_actor)
{
XBT_DEBUG("Start actor %s@'%s'", name.c_str(), host->get_cname());
for (auto const& kv : *properties)
actor->set_property(kv.first, kv.second);
- actor->start(std::move(code));
+ actor->start(code);
return actor;
}
-void create_maestro(simix::ActorCode code)
+void create_maestro(const std::function<void()>& code)
{
/* Create maestro actor and initialize it */
ActorImpl* maestro = new ActorImpl(xbt::string(""), /*host*/ nullptr);
if (not code) {
maestro->context_ = simix_global->context_factory->create_context(simix::ActorCode(), maestro);
} else {
- maestro->context_ = simix_global->context_factory->create_maestro(code, maestro);
+ maestro->context_ = simix_global->context_factory->create_maestro(simix::ActorCode(code), maestro);
}
maestro->simcall.issuer = maestro;
s4u::Actor* ciface() { return &piface_; }
ActorImplPtr init(std::string name, s4u::Host* host);
- ActorImpl* start(simix::ActorCode code);
+ ActorImpl* start(const simix::ActorCode& code);
- static ActorImplPtr create(std::string name, simix::ActorCode code, void* data, s4u::Host* host,
+ static ActorImplPtr create(std::string name, const simix::ActorCode& code, void* data, s4u::Host* host,
std::unordered_map<std::string, std::string>* properties, ActorImpl* parent_actor);
static ActorImplPtr attach(std::string name, void* data, s4u::Host* host,
std::unordered_map<std::string, std::string>* properties);
bool daemon_ = false;
ProcessArg() = default;
- explicit ProcessArg(std::string name, std::function<void()> code, void* data, s4u::Host* host, double kill_time,
- std::shared_ptr<std::unordered_map<std::string, std::string>> properties, bool auto_restart)
+ explicit ProcessArg(std::string name, const std::function<void()>& code, void* data, s4u::Host* host,
+ double kill_time, std::shared_ptr<std::unordered_map<std::string, std::string>> properties,
+ bool auto_restart)
: name(name)
- , code(std::move(code))
+ , code(code)
, data(data)
, host(host)
, kill_time(kill_time)
explicit ProcessArg(s4u::Host* host, ActorImpl* actor)
: name(actor->get_name())
- , code(std::move(actor->code))
+ , code(actor->code)
, data(actor->get_user_data())
, host(host)
, kill_time(actor->get_kill_time())
&ActorImpl::smx_synchro_hook>>
SynchroList;
-XBT_PUBLIC void create_maestro(std::function<void()> code);
+XBT_PUBLIC void create_maestro(const std::function<void()>& code);
} // namespace actor
} // namespace kernel
} // namespace simgrid