From 983b978b89158ac187fab66595bd2fc236e5b1fc Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 5 Mar 2019 23:05:02 +0100 Subject: [PATCH] Use std::function instead of function pointer. --- src/include/xbt/parmap.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/include/xbt/parmap.hpp b/src/include/xbt/parmap.hpp index 0a5f24bdb1..de0177c01b 100644 --- a/src/include/xbt/parmap.hpp +++ b/src/include/xbt/parmap.hpp @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -42,7 +43,7 @@ public: Parmap(const Parmap&) = delete; Parmap& operator=(const Parmap&) = delete; ~Parmap(); - void apply(void (*fun)(T), const std::vector& data); + void apply(std::function&& fun, const std::vector& data); boost::optional next(); private: @@ -146,7 +147,7 @@ private: Synchro* synchro; /**< synchronization object */ std::atomic_uint thread_counter{0}; /**< number of workers that have done the work */ - void (*fun)(const T) = nullptr; /**< function to run in parallel on each element of data */ + std::function fun; /**< function to run in parallel on each element of data */ const std::vector* data = nullptr; /**< parameters to pass to fun in parallel */ std::atomic_uint index; /**< index of the next element of data to pick */ }; @@ -215,10 +216,10 @@ template Parmap::~Parmap() * @param fun the function to call in parallel * @param data each element of this vector will be passed as an argument to fun */ -template void Parmap::apply(void (*fun)(T), const std::vector& data) +template void Parmap::apply(std::function&& fun, const std::vector& data) { /* Assign resources to worker threads (we are maestro here)*/ - this->fun = fun; + this->fun = std::move(fun); this->data = &data; this->index = 0; this->synchro->master_signal(); // maestro runs futex_wake to wake all the minions (the working threads) -- 2.20.1