Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[simix] Use Task instead of std::package_task for timer callbacks
authorGabriel Corona <gabriel.corona@loria.fr>
Fri, 24 Jun 2016 14:40:57 +0000 (16:40 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Fri, 24 Jun 2016 14:40:57 +0000 (16:40 +0200)
include/simgrid/simix.hpp
src/simix/smx_global.cpp

index eb92f42..a4824d0 100644 (file)
@@ -13,7 +13,6 @@
 #include <utility>
 #include <memory>
 #include <functional>
-#include <future>
 
 #include <xbt/function_types.h>
 #include <xbt/future.hpp>
@@ -215,12 +214,12 @@ 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::packaged_task<void()> callback);
+XBT_PUBLIC(smx_timer_t) SIMIX_timer_set(double date, simgrid::xbt::Task<void()> callback);
 
 template<class F> inline
 XBT_PUBLIC(smx_timer_t) SIMIX_timer_set(double date, F callback)
 {
-  return SIMIX_timer_set(date, std::packaged_task<void()>(std::move(callback)));
+  return SIMIX_timer_set(date, simgrid::xbt::Task<void()>(std::move(callback)));
 }
 
 template<class R, class T> inline
index 82691e1..7544d36 100644 (file)
@@ -5,13 +5,14 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include <functional>
-#include <future>
 #include <memory>
 
 #include <signal.h> /* Signal handling */
 #include <stdlib.h>
 #include "src/internal_config.h"
 
+#include <xbt/functional.hpp>
+
 #include "src/surf/surf_interface.hpp"
 #include "src/surf/storage_interface.hpp"
 #include "src/surf/xml/platf.hpp"
@@ -52,10 +53,10 @@ static xbt_heap_t simix_timers = nullptr;
 /** @brief Timer datatype */
 typedef struct s_smx_timer {
   double date = 0.0;
-  std::packaged_task<void()> callback;
+  simgrid::xbt::Task<void()> callback;
 
   s_smx_timer() {}
-  s_smx_timer(double date, std::packaged_task<void()> callback)
+  s_smx_timer(double date, simgrid::xbt::Task<void()> callback)
     : date(date), callback(std::move(callback)) {}
 } s_smx_timer_t;
 
@@ -531,15 +532,14 @@ void SIMIX_run(void)
  *   \param arg Parameters of the function
  *
  */
-smx_timer_t SIMIX_timer_set(double date, void (*function)(void*), void *arg)
+smx_timer_t SIMIX_timer_set(double date, void (*callback)(void*), void *arg)
 {
-  smx_timer_t timer = new s_smx_timer_t(date,
-    std::packaged_task<void()>(std::bind(function, arg)));
+  smx_timer_t timer = new s_smx_timer_t(date, [=](){ callback(arg); });
   xbt_heap_push(simix_timers, timer, date);
   return timer;
 }
 
-smx_timer_t SIMIX_timer_set(double date, std::packaged_task<void()> callback)
+smx_timer_t SIMIX_timer_set(double date, simgrid::xbt::Task<void()> callback)
 {
   smx_timer_t timer = new s_smx_timer_t(date, std::move(callback));
   xbt_heap_push(simix_timers, timer, date);