X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e54471e47acaaa087f58c62c3ec142e911e30d40..ab1a94e98438ed2d29533aca9e613d667237c3d0:/include/simgrid/simix.hpp diff --git a/include/simgrid/simix.hpp b/include/simgrid/simix.hpp index 901081aa1b..eb92f4262b 100644 --- a/include/simgrid/simix.hpp +++ b/include/simgrid/simix.hpp @@ -9,28 +9,44 @@ #include -#include #include #include #include #include #include -#include #include #include +#include #include XBT_PUBLIC(void) simcall_run_kernel(std::function const& code); +/** Execute some code in the kernel and block + * + * run_blocking() is a generic blocking simcall. It is given a callback + * which is executed immediately in the SimGrid kernel. The callback is + * responsible for setting the suitable logic for waking up the process + * when needed. + * + * @ref simix::kernelSync() is a higher level wrapper for this. + */ +XBT_PUBLIC(void) simcall_run_blocking(std::function const& code); + template inline void simcall_run_kernel(F& f) { simcall_run_kernel(std::function(std::ref(f))); } +template inline +void simcall_run_blocking(F& f) +{ + simcall_run_blocking(std::function(std::ref(f))); +} namespace simgrid { + namespace simix { /** Execute some code in the kernel/maestro @@ -40,7 +56,7 @@ namespace simix { * of the operation with respect to other simcalls. */ template -typename std::result_of::type kernel(F&& code) +typename std::result_of::type kernelImmediate(F&& code) { // If we are in the maestro, we take the fast path and execute the // code directly without simcall mashalling/unmarshalling/dispatch: @@ -156,6 +172,14 @@ public: XBT_PUBLIC(void) set_maestro(std::function code); XBT_PUBLIC(void) create_maestro(std::function code); +// What's executed as SIMIX actor code: +typedef std::function ActorCode; + +// Create ActorCode based on argv: +typedef std::function ActorCodeFactory; + +XBT_PUBLIC(void) registerFunction(const char* name, ActorCodeFactory factory); + } } @@ -191,7 +215,13 @@ XBT_PUBLIC(smx_process_t) simcall_process_create(const char *name, xbt_dict_t properties, int auto_restart); -XBT_PUBLIC(smx_timer_t) SIMIX_timer_set(double date, std::function callback); +XBT_PUBLIC(smx_timer_t) SIMIX_timer_set(double date, std::packaged_task callback); + +template inline +XBT_PUBLIC(smx_timer_t) SIMIX_timer_set(double date, F callback) +{ + return SIMIX_timer_set(date, std::packaged_task(std::move(callback))); +} template inline XBT_PUBLIC(smx_timer_t) SIMIX_timer_set(double date, R(*callback)(T*), T* arg)