XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
namespace simgrid {
-namespace simix {
+namespace kernel {
+namespace context {
class UContext;
class SerialUContext;
class ParallelUContext;
class UContextFactory;
-}
-}
+}}}
#if HAVE_THREAD_CONTEXTS
static xbt_parmap_t sysv_parmap;
-static simgrid::simix::ParallelUContext** sysv_workers_context; /* space to save the worker's context in each thread */
+static simgrid::kernel::context::ParallelUContext** sysv_workers_context; /* space to save the worker's context in each thread */
static uintptr_t sysv_threads_working; /* number of threads that have started their work */
static xbt_os_thread_key_t sysv_worker_id_key; /* thread-specific storage for the thread id */
#endif
static unsigned long sysv_process_index = 0; /* index of the next process to run in the
* list of runnable processes */
-static simgrid::simix::UContext* sysv_maestro_context;
+static simgrid::kernel::context::UContext* sysv_maestro_context;
static bool sysv_parallel;
// The name of this function is currently hardcoded in the code (as string).
static void smx_ctx_sysv_wrapper(int first, ...);
namespace simgrid {
-namespace simix {
+namespace kernel {
+namespace context {
class UContext : public Context {
protected:
public:
friend UContextFactory;
UContext(std::function<void()> code,
- void_pfn_smxprocess_t cleanup_func, smx_process_t process);
+ void_pfn_smxprocess_t cleanup_func, smx_actor_t process);
~UContext() override;
};
class SerialUContext : public UContext {
public:
SerialUContext(std::function<void()> code,
- void_pfn_smxprocess_t cleanup_func, smx_process_t process)
+ void_pfn_smxprocess_t cleanup_func, smx_actor_t process)
: UContext(std::move(code), cleanup_func, process)
{}
void stop() override;
class ParallelUContext : public UContext {
public:
ParallelUContext(std::function<void()> code,
- void_pfn_smxprocess_t cleanup_func, smx_process_t process)
+ void_pfn_smxprocess_t cleanup_func, smx_actor_t process)
: UContext(std::move(code), cleanup_func, process)
{}
void stop() override;
UContextFactory();
~UContextFactory() override;
Context* create_context(std::function<void()> code,
- void_pfn_smxprocess_t cleanup, smx_process_t process) override;
+ void_pfn_smxprocess_t cleanup, smx_actor_t process) override;
void run_all() override;
};
xbt_parmap_apply(sysv_parmap,
[](void* arg) {
- smx_process_t process = (smx_process_t) arg;
+ smx_actor_t process = (smx_actor_t) arg;
ParallelUContext* context = static_cast<ParallelUContext*>(process->context);
context->resume();
},
#endif
} else {
// Serial:
- smx_process_t first_process =
- xbt_dynar_get_as(simix_global->process_to_run, 0, smx_process_t);
- sysv_process_index = 1;
- SerialUContext* context =
+ if (xbt_dynar_is_empty(simix_global->process_to_run))
+ return;
+
+ smx_actor_t first_process =
+ xbt_dynar_get_as(simix_global->process_to_run, 0, smx_actor_t);
+ sysv_process_index = 1;
+ SerialUContext* context =
static_cast<SerialUContext*>(first_process->context);
- context->resume();
+ context->resume();
}
}
Context* UContextFactory::create_context(std::function<void()> code,
- void_pfn_smxprocess_t cleanup, smx_process_t process)
+ void_pfn_smxprocess_t cleanup, smx_actor_t process)
{
if (sysv_parallel)
return new_context<ParallelUContext>(std::move(code), cleanup, process);
}
UContext::UContext(std::function<void()> code,
- void_pfn_smxprocess_t cleanup_func, smx_process_t process)
+ void_pfn_smxprocess_t cleanup_func, smx_actor_t process)
: Context(std::move(code), cleanup_func, process)
{
/* if the user provided a function for the process then use it, otherwise it is the context for maestro */
SIMIX_context_stack_delete(this->stack_);
}
-}
-}
+}}} // namespace simgrid::kernel::context
static void smx_ctx_sysv_wrapper(int first, ...)
{
// Rebuild the Context* pointer from the integers:
int ctx_addr[CTX_ADDR_LEN];
- simgrid::simix::UContext* context;
+ simgrid::kernel::context::UContext* context;
ctx_addr[0] = first;
if (CTX_ADDR_LEN > 1) {
va_list ap;
ctx_addr[i] = va_arg(ap, int);
va_end(ap);
}
- memcpy(&context, ctx_addr, sizeof(simgrid::simix::UContext*));
+ memcpy(&context, ctx_addr, sizeof(simgrid::kernel::context::UContext*));
(*context)();
context->stop();
}
namespace simgrid {
-namespace simix {
+namespace kernel {
+namespace context {
void SerialUContext::stop()
{
/* execute the next process */
XBT_DEBUG("Run next process");
next_context = (SerialUContext*) xbt_dynar_get_as(
- simix_global->process_to_run,i, smx_process_t)->context;
+ simix_global->process_to_run,i, smx_actor_t)->context;
}
else {
/* all processes were run, return to maestro */
#if HAVE_THREAD_CONTEXTS
/* determine the next context */
// Get the next soul to embody now:
- smx_process_t next_work = (smx_process_t) xbt_parmap_next(sysv_parmap);
+ smx_actor_t next_work = (smx_actor_t) xbt_parmap_next(sysv_parmap);
ParallelUContext* next_context = nullptr;
// Will contain the next soul to run, either simulated or initial minion's one
ucontext_t* next_stack;
#endif
}
-}
-}
+}}} // namespace simgrid::kernel::context