// (as the ones created for the VM migration). The Java exception will not be catched anywhere.
// Bad things happen currently if these actors get killed, unfortunately.
jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError",
- std::string("Process ") + this->process()->get_cname() + " killed from file JavaContext.cpp");
+ std::string("Process ") + this->get_actor()->get_cname() + " killed from file JavaContext.cpp");
// (remember that throwing a java exception from C does not break the C execution path.
// Instead, it marks the exception to be raised when returning to the Java world and
public:
bool iwannadie = false;
- Context(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process);
+ Context(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t actor);
Context(const Context&) = delete;
Context& operator=(const Context&) = delete;
virtual ~Context();
void operator()() { code_(); }
bool has_code() const { return static_cast<bool>(code_); }
- smx_actor_t process() { return this->actor_; }
+ smx_actor_t get_actor() { return this->actor_; }
void set_cleanup(void_pfn_smxprocess_t cleanup) { cleanup_func_ = cleanup; }
// Scheduling methods
// BoostContext
-BoostContext::BoostContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process,
+BoostContext::BoostContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t actor,
SwappedContextFactory* factory)
- : SwappedContext(std::move(code), cleanup_func, process, factory)
+ : SwappedContext(std::move(code), cleanup_func, actor, factory)
{
/* if the user provided a function for the process then use it, otherwise it is the context for maestro */
/** @brief Userspace context switching implementation based on Boost.Context */
class BoostContext : public SwappedContext {
public:
- BoostContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process,
+ BoostContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t actor,
SwappedContextFactory* factory);
~BoostContext() override;
// RawContext
-RawContext::RawContext(std::function<void()> code, void_pfn_smxprocess_t cleanup, smx_actor_t process,
+RawContext::RawContext(std::function<void()> code, void_pfn_smxprocess_t cleanup, smx_actor_t actor,
SwappedContextFactory* factory)
- : SwappedContext(std::move(code), cleanup, process, factory)
+ : SwappedContext(std::move(code), cleanup, actor, factory)
{
if (has_code()) {
#if PTH_STACKGROWTH == -1
*/
class RawContext : public SwappedContext {
public:
- RawContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process,
+ RawContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t actor,
SwappedContextFactory* factory);
void swap_into(SwappedContext* to) override;
class SwappedContext : public Context {
public:
- SwappedContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process,
+ SwappedContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t get_actor,
SwappedContextFactory* factory);
virtual ~SwappedContext();
}
ThreadContext* ThreadContextFactory::create_context(std::function<void()> code, void_pfn_smxprocess_t cleanup,
- smx_actor_t process, bool maestro)
+ smx_actor_t actor, bool maestro)
{
if (parallel_)
- return this->new_context<ParallelThreadContext>(std::move(code), cleanup, process, maestro);
+ return this->new_context<ParallelThreadContext>(std::move(code), cleanup, actor, maestro);
else
- return this->new_context<SerialThreadContext>(std::move(code), cleanup, process, maestro);
+ return this->new_context<SerialThreadContext>(std::move(code), cleanup, actor, maestro);
}
void ThreadContextFactory::run_all()
ThreadContext::ThreadContext(std::function<void()> code, void_pfn_smxprocess_t cleanup, smx_actor_t actor, bool maestro)
: AttachContext(std::move(code), cleanup, actor), is_maestro_(maestro)
{
- /* If the user provided a function for the process then use it */
+ /* If the user provided a function for the actor then use it */
if (has_code()) {
- /* create and start the process */
+ /* create and start the actor */
this->thread_ = new std::thread(ThreadContext::wrapper, this);
- /* wait the starting of the newly created process */
+ /* wait the starting of the newly created actor */
this->end_.acquire();
}
void SerialThreadContext::run_all()
{
- for (smx_actor_t const& process : simix_global->process_to_run) {
- XBT_DEBUG("Handling %p", process);
- ThreadContext* context = static_cast<ThreadContext*>(process->context_);
+ for (smx_actor_t const& actor : simix_global->process_to_run) {
+ XBT_DEBUG("Handling %p", actor);
+ ThreadContext* context = static_cast<ThreadContext*>(actor->context_);
context->release();
context->wait();
}
void ParallelThreadContext::run_all()
{
- for (smx_actor_t const& process : simix_global->process_to_run)
- static_cast<ThreadContext*>(process->context_)->release();
- for (smx_actor_t const& process : simix_global->process_to_run)
- static_cast<ThreadContext*>(process->context_)->wait();
+ for (smx_actor_t const& actor : simix_global->process_to_run)
+ static_cast<ThreadContext*>(actor->context_)->release();
+ for (smx_actor_t const& actor : simix_global->process_to_run)
+ static_cast<ThreadContext*>(actor->context_)->wait();
}
void ParallelThreadContext::start_hook()
class XBT_PUBLIC ThreadContext : public AttachContext {
public:
- ThreadContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process, bool maestro);
+ ThreadContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t actor, bool maestro);
~ThreadContext() override;
void stop() override;
void suspend() override;
private:
/** A portable thread */
std::thread* thread_ = nullptr;
- /** Semaphore used to schedule/yield the process (not needed when the maestro is in main, but harmless then) */
+ /** Semaphore used to schedule/yield the actor (not needed when the maestro is in main, but harmless then) */
xbt::OsSemaphore begin_{0};
/** Semaphore used to schedule/unschedule (not needed when the maestro is in main, but harmless then) */
xbt::OsSemaphore end_{0};
class XBT_PUBLIC SerialThreadContext : public ThreadContext {
public:
- SerialThreadContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process, bool maestro)
- : ThreadContext(std::move(code), cleanup_func, process, maestro)
+ SerialThreadContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t actor, bool maestro)
+ : ThreadContext(std::move(code), cleanup_func, actor, maestro)
{
}
class ParallelThreadContext : public ThreadContext {
public:
- ParallelThreadContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process,
- bool maestro)
- : ThreadContext(std::move(code), cleanup_func, process, maestro)
+ ParallelThreadContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t actor, bool maestro)
+ : ThreadContext(std::move(code), cleanup_func, actor, maestro)
{
}
ThreadContextFactory();
~ThreadContextFactory() override;
ThreadContext* create_context(std::function<void()> code, void_pfn_smxprocess_t cleanup_func,
- smx_actor_t process) override
+ smx_actor_t actor) override
{
bool maestro = not code;
- return create_context(std::move(code), cleanup_func, process, maestro);
+ return create_context(std::move(code), cleanup_func, actor, maestro);
}
void run_all() override;
// Optional methods:
- ThreadContext* attach(void_pfn_smxprocess_t cleanup_func, smx_actor_t process) override
+ ThreadContext* attach(void_pfn_smxprocess_t cleanup_func, smx_actor_t actor) override
{
- return create_context(std::function<void()>(), cleanup_func, process, false);
+ return create_context(std::function<void()>(), cleanup_func, actor, false);
}
- ThreadContext* create_maestro(std::function<void()> code, smx_actor_t process) override
+ ThreadContext* create_maestro(std::function<void()> code, smx_actor_t actor) override
{
- return create_context(std::move(code), nullptr, process, true);
+ return create_context(std::move(code), nullptr, actor, true);
}
private:
bool parallel_;
- ThreadContext* create_context(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process,
+ ThreadContext* create_context(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t actor,
bool maestro);
};
}}} // namespace
namespace context {
// UContextFactory
-Context* UContextFactory::create_context(std::function<void()> code, void_pfn_smxprocess_t cleanup, smx_actor_t process)
+Context* UContextFactory::create_context(std::function<void()> code, void_pfn_smxprocess_t cleanup, smx_actor_t actor)
{
- return new_context<UContext>(std::move(code), cleanup, process, this);
+ return new_context<UContext>(std::move(code), cleanup, actor, this);
}
// UContext
-UContext::UContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process,
+UContext::UContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t actor,
SwappedContextFactory* factory)
- : SwappedContext(std::move(code), cleanup_func, process, factory)
+ : SwappedContext(std::move(code), cleanup_func, actor, factory)
{
/* if the user provided a function for the process then use it, otherwise it is the context for maestro */
if (has_code()) {
#if SIMGRID_HAVE_MC
if (MC_is_active() && has_code()) {
- MC_register_stack_area(get_stack(), process, &(this->uc_), smx_context_usable_stack_size);
+ MC_register_stack_area(get_stack(), actor, &(this->uc_), smx_context_usable_stack_size);
}
#endif
}
class UContext : public SwappedContext {
public:
- UContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process,
+ UContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t actor,
SwappedContextFactory* factory);
void swap_into(SwappedContext* to) override;
if (self_context == nullptr)
return simgrid::s4u::ActorPtr();
- return self_context->process()->iface();
+ return self_context->get_actor()->iface();
}
ActorPtr Actor::create(std::string name, s4u::Host* host, std::function<void()> code)
{
smx_context_t self_context = simgrid::kernel::context::Context::self();
- return (self_context != nullptr) ? self_context->process() : nullptr;
+ return (self_context != nullptr) ? self_context->get_actor() : nullptr;
}
/**
if (context == nullptr)
xbt_die("Not a suitable context");
- SIMIX_process_cleanup(context->process());
+ SIMIX_process_cleanup(context->get_actor());
context->attach_stop();
}