From 957359023a54d7fcf4836b36fcd998594ae28bc9 Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Thu, 2 Jul 2015 19:38:17 +0200 Subject: [PATCH] more work --- include/Continuable.h | 127 ++++++++++++++++++++++-------------------- 1 file changed, 68 insertions(+), 59 deletions(-) diff --git a/include/Continuable.h b/include/Continuable.h index 256ffcf..f84990a 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -33,7 +33,7 @@ class Continuable; namespace detail { /// Trait to identify continuable types - template + template struct is_continuable : std::false_type { }; @@ -42,7 +42,7 @@ namespace detail : std::true_type { }; /// Creates an empty callback. - template + template struct create_empty_callback; template @@ -57,14 +57,17 @@ namespace detail } }; - template + template struct unary_chainer_t; template struct multiple_when_all_chainer_t; + template + class multiple_result_storage_t; + /// Functional traits forward declaration. - template + template struct functional_traits; } // detail @@ -78,6 +81,9 @@ class Continuable template friend class Continuable; + template + friend class detail::multiple_result_storage_t; + public: typedef Callback<_ATy...> CallbackFunction; typedef std::function&&)> ForwardFunction; @@ -231,7 +237,7 @@ public: namespace detail { - template + template struct ContinuableFactory; template @@ -300,7 +306,7 @@ namespace detail typedef fu::argument_type_of_t callback_arguments_t; }; - template + template struct concat_identities; template @@ -309,7 +315,7 @@ namespace detail typedef fu::identity type; }; - template + template struct identity_to_tuple; template @@ -318,7 +324,7 @@ namespace detail typedef std::tuple type; }; - template + template struct void_wrap_trait; /// Trait needed for functional_traits::remove_void_trait @@ -489,6 +495,59 @@ namespace detail multiple_result_maker<0, fu::identity<>, fu::identity<>, Args...>; }; + template + class multiple_result_storage_t, fu::identity<_RTy...>, fu::identity<_PTy...>> + { + std::size_t partitions_left; + + std::tuple<_RTy...> result; + + Callback<_RTy...> callback; + + std::mutex lock; + + template + struct result_store_sequencer; + + template + struct result_store_sequencer < fu::sequence, Offset > + { + // Do nothing + inline static void store(std::tuple<_RTy...>& result) + { + } + + // Store the args in the result tuple + template + inline static void store(std::tuple<_RTy...>& result, Args&&... args) + { + } + }; + + public: + multiple_result_storage_t(std::size_t partitions, Callback<_RTy...> callback_) + : partitions_left(partitions), callback(callback_) { } + + template + void store_result(Args&&... args) + { + result_store_sequencer< + fu::sequence_of_t, + Position + >::store(result, std::forward(args)...); + + // TODO Improve the lock here + std::lock_guard guard(lock); + { + // If all partitions have completed invoke the final callback. + if (--partitions_left == 0) + { + + } + } + } + }; + template struct multiple_when_all_chainer_t_make_result; @@ -501,57 +560,7 @@ namespace detail typedef functional_traits<_ATy...> traits_t; - class ResultStorage - { - std::size_t partitions_left; - - std::tuple<_RTy...> result; - - Callback<_RTy...> callback; - - std::mutex lock; - - template - struct result_store_sequencer; - - template - struct result_store_sequencer, Offset> - { - // Do nothing - inline static void store(std::tuple<_RTy...>& result) - { - } - - // Store the args in the result tuple - template - inline static void store(std::tuple<_RTy...>& result, Args&&... args) - { - } - }; - - public: - ResultStorage(std::size_t partitions, Callback<_RTy...> callback_) - : partitions_left(partitions), callback(callback_) { } - - template - void store_result(Args&&... args) - { - result_store_sequencer< - fu::sequence_of_t, - Position - >::store(result, std::forward(args)...); - - // TODO Improve the lock here - std::lock_guard guard(lock); - { - // If all partitions have completed invoke the final callback. - if (--partitions_left == 0) - { - - } - } - } - }; + typedef multiple_result_storage_t, fu::identity<_RTy...>, fu::identity<_PTy...>> ResultStorage; typedef std::shared_ptr shared_result_t;