#include <stdarg.h>
+#include <functional>
+
#include "xbt/parmap.h"
-#include "smx_private.h"
-#include "smx_private.hpp"
+#include "src/simix/smx_private.h"
+#include "src/simix/smx_private.hpp"
#include "src/internal_config.h"
#include "src/context_sysv_config.h" /* loads context system definitions */
#include "mc/mc.h"
* Makecontext expects integer arguments, we the context
* variable is decomposed into a serie of integers and
* each integer is passed as argument to makecontext. */
-XBT_PRIVATE
-void simgrid_makecontext(ucontext* ucp, void (*func)(int first, ...), void* arg)
+static
+void simgrid_makecontext(ucontext_t* ucp, void (*func)(int first, ...), void* arg)
{
int ctx_addr[CTX_ADDR_LEN];
memcpy(ctx_addr, &arg, sizeof(void*));
char *stack_ = nullptr; /* the thread stack */
public:
friend UContextFactory;
- UContext(xbt_main_func_t code,
- int argc, char **argv,
- void_pfn_smxprocess_t cleanup_func,
- smx_process_t process);
+ UContext(std::function<void()> code,
+ void_pfn_smxprocess_t cleanup_func, smx_process_t process);
~UContext();
protected:
static void wrapper(int first, ...);
class SerialUContext : public UContext {
public:
- SerialUContext(xbt_main_func_t code,
- int argc, char **argv,
- void_pfn_smxprocess_t cleanup_func,
- smx_process_t process)
- : UContext(code, argc, argv, cleanup_func, process)
+ SerialUContext(std::function<void()> code,
+ void_pfn_smxprocess_t cleanup_func, smx_process_t process)
+ : UContext(std::move(code), cleanup_func, process)
{}
void stop() override;
void suspend() override;
class ParallelUContext : public UContext {
public:
- ParallelUContext(xbt_main_func_t code,
- int argc, char **argv,
- void_pfn_smxprocess_t cleanup_func,
- smx_process_t process)
- : UContext(code, argc, argv, cleanup_func, process)
+ ParallelUContext(std::function<void()> code,
+ void_pfn_smxprocess_t cleanup_func, smx_process_t process)
+ : UContext(std::move(code), cleanup_func, process)
{}
void stop() override;
void suspend() override;
UContextFactory();
virtual ~UContextFactory();
- virtual Context* create_context(
- xbt_main_func_t, int, char **, void_pfn_smxprocess_t,
- smx_process_t process
- ) override;
+ virtual Context* create_context(std::function<void()> code,
+ void_pfn_smxprocess_t, smx_process_t process) override;
void run_all() override;
};
}
}
-Context* UContextFactory::create_context(
- xbt_main_func_t code, int argc, char ** argv,
- void_pfn_smxprocess_t cleanup,
- smx_process_t process
- )
+Context* UContextFactory::create_context(std::function<void()> code,
+ void_pfn_smxprocess_t cleanup, smx_process_t process)
{
if (sysv_parallel)
- return new_context<ParallelUContext>(code, argc, argv, cleanup, process);
+ return new_context<ParallelUContext>(std::move(code), cleanup, process);
else
- return new_context<SerialUContext>(code, argc, argv, cleanup, process);
+ return new_context<SerialUContext>(std::move(code), cleanup, process);
}
-UContext::UContext(xbt_main_func_t code,
- int argc, char **argv,
- void_pfn_smxprocess_t cleanup_func,
- smx_process_t process)
- : Context(code, argc, argv, cleanup_func, process)
+UContext::UContext(std::function<void()> code,
+ void_pfn_smxprocess_t cleanup_func, smx_process_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 */
- if (code) {
+ if (has_code()) {
this->stack_ = (char*) SIMIX_context_stack_new();
getcontext(&this->uc_);
this->uc_.uc_link = nullptr;
#ifdef HAVE_MC
if (MC_is_active() && code) {
- MC_register_stack_area(this->stack_, context->process,
+ MC_register_stack_area(this->stack_, process,
&(this->uc_), smx_context_usable_stack_size);
}
#endif