From 630d24de439f73193f6a72f7c097e6feed3d9921 Mon Sep 17 00:00:00 2001 From: FritzFlorian Date: Tue, 9 Jul 2019 16:43:39 +0200 Subject: [PATCH] Restructure to allow a clean interface for end users. We need some tricks in template programming to have a clean user facing API while internally using our classes with more capabilities. --- app/playground/main.cpp | 12 ++++-------- lib/pls/CMakeLists.txt | 12 ++++++------ lib/pls/include/pls/dataflow/graph.h | 9 ++++++--- lib/pls/include/pls/dataflow/input.h | 41 ----------------------------------------- lib/pls/include/pls/dataflow/inputs.h | 14 ++++---------- lib/pls/include/pls/dataflow/internal/input.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ lib/pls/include/pls/dataflow/internal/output.h | 37 +++++++++++++++++++++++++++++++++++++ lib/pls/include/pls/dataflow/internal/token.h | 32 ++++++++++++++++++++++++++++++++ lib/pls/include/pls/dataflow/output.h | 35 ----------------------------------- lib/pls/include/pls/dataflow/outputs.h | 17 +++++------------ lib/pls/include/pls/dataflow/token.h | 30 ------------------------------ 11 files changed, 139 insertions(+), 145 deletions(-) delete mode 100644 lib/pls/include/pls/dataflow/input.h create mode 100644 lib/pls/include/pls/dataflow/internal/input.h create mode 100644 lib/pls/include/pls/dataflow/internal/output.h create mode 100644 lib/pls/include/pls/dataflow/internal/token.h delete mode 100644 lib/pls/include/pls/dataflow/output.h delete mode 100644 lib/pls/include/pls/dataflow/token.h diff --git a/app/playground/main.cpp b/app/playground/main.cpp index 2a48764..e35d4a3 100644 --- a/app/playground/main.cpp +++ b/app/playground/main.cpp @@ -1,17 +1,13 @@ // Headers are available because we added the pls target #include - #include +#include #include -#include -#include +#include int main() { - pls::dataflow::inputs in; - pls::dataflow::outputs out1; - pls::dataflow::outputs out2; + using namespace pls::dataflow; - out1.get<0>().connect(in.get<0>()); - out2.get<0>().connect(in.get<1>()); + graph, outputs, 8> graph; } diff --git a/lib/pls/CMakeLists.txt b/lib/pls/CMakeLists.txt index 3dae953..45b0740 100644 --- a/lib/pls/CMakeLists.txt +++ b/lib/pls/CMakeLists.txt @@ -10,12 +10,12 @@ add_library(pls STATIC include/pls/algorithms/scan_impl.h include/pls/dataflow/dataflow.h - include/pls/dataflow/token.h + include/pls/dataflow/internal/token.h include/pls/dataflow/graph.h - include/pls/dataflow/inputs.h - include/pls/dataflow/outputs.h - include/pls/dataflow/input.h - include/pls/dataflow/output.h + include/pls/dataflow/internal/inputs.h + include/pls/dataflow/internal/outputs.h + include/pls/dataflow/internal/input.h + include/pls/dataflow/internal/output.h include/pls/internal/base/spin_lock.h include/pls/internal/base/tas_spin_lock.h src/internal/base/tas_spin_lock.cpp @@ -47,7 +47,7 @@ add_library(pls STATIC include/pls/internal/scheduling/scheduler_impl.h include/pls/internal/scheduling/task.h src/internal/scheduling/task.cpp include/pls/internal/scheduling/scheduler_memory.h src/internal/scheduling/scheduler_memory.cpp - include/pls/internal/scheduling/lambda_task.h) + include/pls/internal/scheduling/lambda_task.h include/pls/dataflow/inputs.h include/pls/dataflow/outputs.h) # Add everything in `./include` to be in the include path of this project target_include_directories(pls PUBLIC diff --git a/lib/pls/include/pls/dataflow/graph.h b/lib/pls/include/pls/dataflow/graph.h index 1f94b02..1a05a57 100644 --- a/lib/pls/include/pls/dataflow/graph.h +++ b/lib/pls/include/pls/dataflow/graph.h @@ -2,14 +2,17 @@ #ifndef PLS_DATAFLOW_GRAPH_H_ #define PLS_DATAFLOW_GRAPH_H_ +#include "inputs.h" +#include "outputs.h" + namespace pls { namespace dataflow { -template< +template class graph { - + using internal_inputs = typename I::template internal_inputs

; + using internal_outputs = typename O::template internal_outputs

; }; - } } diff --git a/lib/pls/include/pls/dataflow/input.h b/lib/pls/include/pls/dataflow/input.h deleted file mode 100644 index c47581a..0000000 --- a/lib/pls/include/pls/dataflow/input.h +++ /dev/null @@ -1,41 +0,0 @@ - -#ifndef PLS_DATAFLOW_INPUT_H_ -#define PLS_DATAFLOW_INPUT_H_ - -#include "token.h" - -#include "pls/internal/base/error_handling.h" - -namespace pls { -namespace dataflow { - -template -class input { - template - friend - class output; - - token token_; - bool filled_; - bool connected_; - - void connect() { - if (connected_) { - PLS_ERROR("Must only connect on input once. Disconnect the output pointing to it before reconnecting.") - } - connected_ = true; - } - - public: - input() : filled_{false}, connected_{false} {}; - - bool has_token(color color) const { - return filled_ && token_.color() == color; - } - const token &get_token() const { return token_; } -}; - -} -} - -#endif //PLS_DATAFLOW_INPUT_H_ diff --git a/lib/pls/include/pls/dataflow/inputs.h b/lib/pls/include/pls/dataflow/inputs.h index 24f7d95..c7d453e 100644 --- a/lib/pls/include/pls/dataflow/inputs.h +++ b/lib/pls/include/pls/dataflow/inputs.h @@ -4,21 +4,15 @@ #include -#include "input.h" +#include "internal/inputs.h" namespace pls { namespace dataflow { template -class inputs { - using values_type = std::tuple, input...>; - values_type values_; - - public: - template - typename std::tuple_element::type &get() { - return std::get(values_); - } +struct inputs { + template + using internal_inputs = internal::inputs; }; } diff --git a/lib/pls/include/pls/dataflow/internal/input.h b/lib/pls/include/pls/dataflow/internal/input.h new file mode 100644 index 0000000..fba2a54 --- /dev/null +++ b/lib/pls/include/pls/dataflow/internal/input.h @@ -0,0 +1,45 @@ + +#ifndef PLS_DATAFLOW_INTERNAL_INPUT_H_ +#define PLS_DATAFLOW_INTERNAL_INPUT_H_ + +#include "token.h" + +#include "pls/internal/base/error_handling.h" + +namespace pls { +namespace dataflow { +namespace internal { + +template +class input { + template + friend + class output; + + token token_; + bool filled_; + bool connected_; + + void connect() { + if (connected_) { + PLS_ERROR("Must only connect on input once. Disconnect the output pointing to it before reconnecting.") + } + connected_ = true; + } + + input() : filled_{false}, connected_{false} {}; + + bool has_token(token_color color) const { + return filled_ && token_.color() == color; + } + const token &get_token() const { return token_; } + + public: + +}; + +} +} +} + +#endif //PLS_DATAFLOW_INTERNAL_INPUT_H_ diff --git a/lib/pls/include/pls/dataflow/internal/output.h b/lib/pls/include/pls/dataflow/internal/output.h new file mode 100644 index 0000000..eb19dce --- /dev/null +++ b/lib/pls/include/pls/dataflow/internal/output.h @@ -0,0 +1,37 @@ + +#ifndef PLS_DATAFLOW_INTERNAL_OUTPUT_H_ +#define PLS_DATAFLOW_INTERNAL_OUTPUT_H_ + +#include "token.h" +#include "input.h" + +#include "pls/internal/base/error_handling.h" + +namespace pls { +namespace dataflow { +namespace internal { + +template +class output { + input *target_; + bool connected_; + + public: + output() : target_{nullptr}, connected_{false} {}; + + void connect(input &target) { + if (connected_) { + PLS_ERROR("Must only connect output once. Please disconnect it before reconnecting.") + } + + target.connect(); + target_ = ⌖ + connected_ = true; + } +}; + +} +} +} + +#endif //PLS_DATAFLOW_INTERNAL_OUTPUT_H_ diff --git a/lib/pls/include/pls/dataflow/internal/token.h b/lib/pls/include/pls/dataflow/internal/token.h new file mode 100644 index 0000000..b0c609a --- /dev/null +++ b/lib/pls/include/pls/dataflow/internal/token.h @@ -0,0 +1,32 @@ + +#ifndef PLS_DATAFLOW_INTERNAL_TOKEN_H_ +#define PLS_DATAFLOW_INTERNAL_TOKEN_H_ + +namespace pls { +namespace dataflow { +namespace internal { + +/** + * Parallel invocations of the same sub-graph are usually working with some kind of coloring + * for tokens to distinguishe different invocations. As this concept is abstract and we could + * change it in the future (for e.g. more advanced features/dataflows) we encapsulate it. + */ +struct token_color { + unsigned int clock_; +}; + +template +class token { + T value_; + token_color color_; + + public: + T value() const { return value_; } + token_color color() const { return color_; } +}; + +} +} +} + +#endif //PLS_DATAFLOW_INTERNAL_TOKEN_H_ diff --git a/lib/pls/include/pls/dataflow/output.h b/lib/pls/include/pls/dataflow/output.h deleted file mode 100644 index 2c2c3cb..0000000 --- a/lib/pls/include/pls/dataflow/output.h +++ /dev/null @@ -1,35 +0,0 @@ - -#ifndef PLS_DATAFLOW_OUTPUT_H_ -#define PLS_DATAFLOW_OUTPUT_H_ - -#include "token.h" -#include "input.h" - -#include "pls/internal/base/error_handling.h" - -namespace pls { -namespace dataflow { - -template -class output { - input *target_; - bool connected_; - - public: - output() : target_{nullptr}, connected_{false} {}; - - void connect(input &target) { - if (connected_) { - PLS_ERROR("Must only connect output once. Please disconnect it before reconnecting.") - } - - target.connect(); - target_ = ⌖ - connected_ = true; - } -}; - -} -} - -#endif //PLS_DATAFLOW_OUTPUT_H_ diff --git a/lib/pls/include/pls/dataflow/outputs.h b/lib/pls/include/pls/dataflow/outputs.h index 68f1f20..e7a5a80 100644 --- a/lib/pls/include/pls/dataflow/outputs.h +++ b/lib/pls/include/pls/dataflow/outputs.h @@ -2,23 +2,16 @@ #ifndef PLS_DATAFLOW_OUTPUTS_H_ #define PLS_DATAFLOW_OUTPUTS_H_ -#include - -#include "output.h" +#include "internal/outputs.h" +#include "outputs.h" namespace pls { namespace dataflow { template -class outputs { - using values_type = std::tuple, output...>; - values_type values_; - - public: - template - typename std::tuple_element::type &get() { - return std::get(values_); - } +struct outputs { + template + using internal_outputs = internal::outputs; }; } diff --git a/lib/pls/include/pls/dataflow/token.h b/lib/pls/include/pls/dataflow/token.h deleted file mode 100644 index 6492944..0000000 --- a/lib/pls/include/pls/dataflow/token.h +++ /dev/null @@ -1,30 +0,0 @@ - -#ifndef PLS_DATAFLOW_TOKEN_H_ -#define PLS_DATAFLOW_TOKEN_H_ - -namespace pls { -namespace dataflow { - -/** - * Parallel invocations of the same sub-graph are usually working with some kind of coloring - * for tokens to distinguishe different invocations. As this concept is abstract and we could - * change it in the future (for e.g. more advanced features/dataflows) we encapsulate it. - */ -struct color { - unsigned int clock_; -}; - -template -class token { - T value_; - color color_; - - public: - T value() const { return value_; } - color color() const { return color_; } -}; - -} -} - -#endif //PLS_DATAFLOW_TOKEN_H_ -- libgit2 0.26.0