-/* Copyright (c) 2009-2015. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2009-2017. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-/* \file UContext.cpp Context switching with ucontexts from System V */
+/* \file UContext.cpp Context switching with ucontexts from System V */
-#include <stdarg.h>
-
-#include <functional>
#include <ucontext.h> /* context relative declarations */
-#include "xbt/parmap.h"
+#include "src/simix/ActorImpl.hpp"
#include "src/simix/smx_private.h"
-#include "src/internal_config.h"
+#include "xbt/parmap.h"
#include "mc/mc.h"
+#include "src/mc/mc_ignore.h"
+
/** Many integers are needed to store a pointer
*
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;
};
void UContextFactory::run_all()
{
if (sysv_parallel) {
- #if HAVE_THREAD_CONTEXTS
+#if HAVE_THREAD_CONTEXTS
sysv_threads_working = 0;
// Parmap_apply ensures that every working thread get an index in the
// process_to_run array (through an atomic fetch_and_add),
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();
},
simix_global->process_to_run);
- #else
+#else
xbt_die("You asked for a parallel execution, but you don't have any threads.");
- #endif
+#endif
} else {
// Serial:
if (xbt_dynar_is_empty(simix_global->process_to_run))
return;
- smx_process_t first_process =
- xbt_dynar_get_as(simix_global->process_to_run, 0, smx_process_t);
+ 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);
+ SerialUContext* context = static_cast<SerialUContext*>(first_process->context);
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 */
sysv_maestro_context = this;
}
-#if HAVE_MC
+#if SIMGRID_HAVE_MC
if (MC_is_active() && has_code()) {
MC_register_stack_area(this->stack_, process,
&(this->uc_), smx_context_usable_stack_size);
/* 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;
- }
- else {
+ simix_global->process_to_run,i, smx_actor_t)->context;
+ } else {
/* all processes were run, return to maestro */
XBT_DEBUG("No more process to run");
next_context = (SerialUContext*) sysv_maestro_context;
#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;
// There is a next soul to embody (ie, a next process to resume)
XBT_DEBUG("Run next process");
next_context = (ParallelUContext*) next_work->context;
- }
- else {
+ } else {
// All processes were run, go to the barrier
XBT_DEBUG("No more processes to run");
// Get back the identity of my body that was stored when starting