diff --git a/include/hlslib/xilinx/Simulation.h b/include/hlslib/xilinx/Simulation.h index 435df8b..a0d5b61 100644 --- a/include/hlslib/xilinx/Simulation.h +++ b/include/hlslib/xilinx/Simulation.h @@ -36,6 +36,7 @@ namespace hlslib { #ifdef HLSLIB_SYNTHESIS #define HLSLIB_DATAFLOW_INIT() #define HLSLIB_DATAFLOW_FUNCTION(func, ...) func(__VA_ARGS__) +#define HLSLIB_FREERUNNING_FUNCTION(func, ...) func(__VA_ARGS__) #define HLSLIB_DATAFLOW_FINALIZE() #else namespace { @@ -65,24 +66,34 @@ class _Dataflow { public: template - void AddFunction(Ret (*func)(Args...), non_deducible_t... args) { - threads_.emplace_back(func, passed_by(std::forward(args), + void AddDataflowFunction(Ret (*func)(Args...), non_deducible_t... args) { + df_threads_.emplace_back(func, passed_by(std::forward(args), + std::is_reference{})...); + } + + template + void AddFreeRunningFunction(Ret (*func)(Args...), non_deducible_t... args) { + auto lambda = [](auto f, auto ...params){while(1){f(params...);}}; + fr_threads_.emplace_back(lambda, func, passed_by(std::forward(args), std::is_reference{})...); } inline void Join() { - for (auto& t : threads_) { + for (auto& t : df_threads_) { t.join(); } - threads_.clear(); + df_threads_.clear(); } private: - std::vector threads_{}; + std::vector df_threads_{}; + std::vector fr_threads_{}; }; #define HLSLIB_DATAFLOW_INIT() ::hlslib::_Dataflow __hlslib_dataflow_context; #define HLSLIB_DATAFLOW_FUNCTION(func, ...) \ - __hlslib_dataflow_context.AddFunction(func, __VA_ARGS__) + __hlslib_dataflow_context.AddDataflowFunction(func, __VA_ARGS__) +#define HLSLIB_FREERUNNING_FUNCTION(func, ...) \ + __hlslib_dataflow_context.AddFreeRunningFunction(func, __VA_ARGS__) #define HLSLIB_DATAFLOW_FINALIZE() __hlslib_dataflow_context.Join(); } // namespace #endif