Skip to content

Commit

Permalink
fix issue taskflow#446 byy adding workround for visual studio 2017
Browse files Browse the repository at this point in the history
  • Loading branch information
qingfengxia committed Nov 27, 2022
1 parent a7bde2f commit ac8433e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
9 changes: 8 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ list(APPEND TF_EXAMPLES
text_pipeline
taskflow_pipeline
parallel_graph_pipeline
parallel_data_pipeline
run
run_and_wait
runtime
Expand All @@ -34,6 +33,14 @@ list(APPEND TF_EXAMPLES
cancel_async
)

if (MSVC)
if(MSVC_VERSION VERSION_LESS 1920)
message("visual studio 2017 can not compile example: parallel_data_pipeline, skip it")
endif()
else()
list(append TF_EXAMPLES parallel_data_pipeline)
endif()

foreach(example IN LISTS TF_EXAMPLES)
add_executable(${example} ${example}.cpp)
target_link_libraries(
Expand Down
30 changes: 27 additions & 3 deletions taskflow/core/executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,9 @@ class Executor {
template <typename P>
void _loop_until(Worker&, P&&);

template <typename F, bool IsVoidRet, typename... ArgsT>
auto _named_async_T(const std::string& name, F&& f, ArgsT&&... args);

template <typename C, std::enable_if_t<is_cudaflow_task_v<C>, void>* = nullptr>
void _invoke_cudaflow_task_entry(Node*, C&&);

Expand Down Expand Up @@ -842,9 +845,16 @@ inline Worker* Executor::_this_worker() {
return itr == _wids.end() ? nullptr : &_workers[itr->second];
}

// Function: named_async
template <typename F, typename... ArgsT>
auto Executor::named_async(const std::string& name, F&& f, ArgsT&&... args) {
// workaround for visual studio 2017, see details in issues#446
return _named_async_T<F, std::is_same_v<std::invoke_result_t<F, ArgsT...>, void>, ArgsT...>
(name, std::forward<F>(f), std::forward<ArgsT>(args)...);
}

// Function: named_async
template <typename F, bool IsVoidRet, typename... ArgsT>
auto Executor::_named_async_T(const std::string& name, F&& f, ArgsT&&... args) {

_increment_topology();

Expand All @@ -861,7 +871,7 @@ auto Executor::named_async(const std::string& name, F&& f, ArgsT&&... args) {
std::in_place_type_t<Node::Async>{},
[p=make_moc(std::move(p)), f=std::forward<F>(f), args...]
(bool cancel) mutable {
if constexpr(std::is_same_v<R, void>) {
if constexpr(IsVoidRet) {
if(!cancel) {
f(args...);
}
Expand Down Expand Up @@ -2040,6 +2050,20 @@ auto Subflow::named_async(const std::string& name, F&& f, ArgsT&&... args) {
// Function: _named_async
template <typename F, typename... ArgsT>
auto Subflow::_named_async(
Worker& w,
const std::string& name,
F&& f,
ArgsT&&... args
) {
// workaround for visual studio 2017, see details in discussion in issues#446
// by adding an extra function call wrapper, because type_trait not working in lambda
return _named_async_T<F, std::is_same_v<std::invoke_result_t<F, ArgsT...>, void>, ArgsT...>
(w, name, std::forward<F>(f), std::forward<ArgsT>(args)...);
}

// workaround
template <typename F, bool IsVoidRet, typename... ArgsT>
auto Subflow::_named_async_T(
Worker& w,
const std::string& name,
F&& f,
Expand All @@ -2061,7 +2085,7 @@ auto Subflow::_named_async(
std::in_place_type_t<Node::Async>{},
[p=make_moc(std::move(p)), f=std::forward<F>(f), args...]
(bool cancel) mutable {
if constexpr(std::is_same_v<R, void>) {
if constexpr(IsVoidRet) {
if(!cancel) {
f(args...);
}
Expand Down
3 changes: 3 additions & 0 deletions taskflow/core/flow_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,9 @@ class Subflow : public FlowBuilder {
template <typename F, typename... ArgsT>
auto _named_async(Worker& w, const std::string& name, F&& f, ArgsT&&... args);

template <typename F, bool IsVoidRet, typename... ArgsT>
auto _named_async_T(Worker& w, const std::string& name, F&& f, ArgsT&&... args);

template <typename F, typename... ArgsT>
void _named_silent_async(Worker& w, const std::string& name, F&& f, ArgsT&&... args);
};
Expand Down
9 changes: 8 additions & 1 deletion unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ list(APPEND TF_UNITTESTS
pipelines
scalable_pipelines
runtimes
data_pipelines
workers
)

if (MSVC)
if(MSVC_VERSION VERSION_LESS 1920)
message("visual studio 2017 can not compile unittest: data_pipelines, skip it")
endif()
else()
list(append TF_UNITTESTS data_pipelines)
endif()

foreach(unittest IN LISTS TF_UNITTESTS)
add_executable(${unittest} ${unittest}.cpp)
target_link_libraries(${unittest} ${PROJECT_NAME} tf::default_settings)
Expand Down

0 comments on commit ac8433e

Please sign in to comment.