1111#include < atomic>
1212#include < functional>
1313#include < memory>
14+ #include < utility>
1415
1516#include " tbb/concurrent_vector.h"
1617#include " tbb/queuing_mutex.h"
1718#include " tbb/spin_mutex.h"
1819
19- #include " Observer.h"
20+ #include " react/Observer.h"
21+ #include " react/Options.h"
22+ #include " react/Traits.h"
2023
24+ #include " react/common/ContinuationInput.h"
2125#include " react/common/Types.h"
26+
2227#include " react/logging/EventLog.h"
2328#include " react/logging/EventRecords.h"
2429
2530#include " react/propagation/TopoSortEngine.h"
2631
2732/* **********************************/ REACT_BEGIN /* ***********************************/
2833
29- template <typename D, typename S>
30- class RSignal ;
31-
32- template <typename D, typename S>
33- class RVarSignal ;
34-
35- template <typename D, typename S>
36- using RRefSignal = RSignal<D,std::reference_wrapper<S>>;
37-
38- template <typename D, typename S>
39- using RVarRefSignal = RVarSignal<D,std::reference_wrapper<S>>;
40-
41- template <typename D, typename E>
42- class REvents ;
43-
44- template <typename D, typename E>
45- class REventSource ;
46-
4734enum class EventToken ;
4835
4936template
@@ -55,186 +42,10 @@ template
5542auto MakeSignal (F&& func, const RSignal<D,TArgs>& ... args)
5643 -> RSignal<D, typename std::result_of<F(TArgs...)>::type>;
5744
58- // //////////////////////////////////////////////////////////////////////////////////////
59- // / IsSignalT
60- // //////////////////////////////////////////////////////////////////////////////////////
61- template <typename D, typename T>
62- struct IsSignalT { static const bool value = false ; };
63-
64- template <typename D, typename T>
65- struct IsSignalT <D, RSignal<D,T>> { static const bool value = true ; };
66-
67- template <typename D, typename T>
68- struct IsSignalT <D, RVarSignal<D,T>> { static const bool value = true ; };
69-
70- // //////////////////////////////////////////////////////////////////////////////////////
71- // / IsEventT
72- // //////////////////////////////////////////////////////////////////////////////////////
73- template <typename D, typename T>
74- struct IsEventT { static const bool value = false ; };
75-
76- template <typename D, typename T>
77- struct IsEventT <D, REvents<D,T>> { static const bool value = true ; };
78-
79- template <typename D, typename T>
80- struct IsEventT <D, REventSource<D,T>> { static const bool value = true ; };
81-
82- /* ***********************************/ REACT_END /* ************************************/
83-
84- /* ********************************/ REACT_IMPL_BEGIN /* ********************************/
85-
86- // //////////////////////////////////////////////////////////////////////////////////////
87- // / ContinuationInput
88- // //////////////////////////////////////////////////////////////////////////////////////
89- class ContinuationInput
90- {
91- public:
92- using InputClosureT = std::function<void ()>;
93- using InputVectT = tbb::concurrent_vector<InputClosureT>;
94-
95- // Note: Shouldn't this be generated by default? Apparently it isn't.
96- inline ContinuationInput& operator =(ContinuationInput&& other)
97- {
98- bufferedInputsPtr_ = std::move (other.bufferedInputsPtr_ );
99- return *this ;
100- }
101-
102- inline bool IsEmpty () const { return bufferedInputsPtr_ == nullptr ; }
103-
104- template <typename F>
105- void Add (F&& input)
106- {
107- if (bufferedInputsPtr_ == nullptr )
108- bufferedInputsPtr_ = std::unique_ptr<InputVectT>(new InputVectT ());
109- bufferedInputsPtr_->push_back (std::forward<F>(input));
110- }
111-
112- inline void Execute ()
113- {
114- if (bufferedInputsPtr_ != nullptr )
115- {
116- for (auto f : *bufferedInputsPtr_)
117- f ();
118- bufferedInputsPtr_->clear ();
119- }
120- }
121-
122- private:
123- std::unique_ptr<InputVectT> bufferedInputsPtr_ = nullptr ;
124- };
125-
126- /* *********************************/ REACT_IMPL_END /* *********************************/
127-
128- /* **********************************/ REACT_BEGIN /* ***********************************/
129-
130- // //////////////////////////////////////////////////////////////////////////////////////
131- // / CommitFlags
132- // //////////////////////////////////////////////////////////////////////////////////////
133- enum ETurnFlags
134- {
135- enable_input_merging = 1 << 0
136- };
137-
13845/* ***********************************/ REACT_END /* ************************************/
13946
14047/* ********************************/ REACT_IMPL_BEGIN /* ********************************/
14148
142- // //////////////////////////////////////////////////////////////////////////////////////
143- // / EngineInterface
144- // //////////////////////////////////////////////////////////////////////////////////////
145- template
146- <
147- typename D,
148- typename TEngine
149- >
150- struct EngineInterface
151- {
152- using NodeInterface = typename TEngine::NodeInterface;
153- using TurnInterface = typename TEngine::TurnInterface;
154-
155- static TEngine& Engine ()
156- {
157- static TEngine engine;
158- return engine;
159- }
160-
161- static void OnNodeCreate (NodeInterface& node)
162- {
163- D::Log ().template Append <NodeCreateEvent>(GetObjectId (node), node.GetNodeType ());
164- Engine ().OnNodeCreate (node);
165- }
166-
167- static void OnNodeDestroy (NodeInterface& node)
168- {
169- D::Log ().template Append <NodeDestroyEvent>(GetObjectId (node));
170- Engine ().OnNodeDestroy (node);
171- }
172-
173- static void OnNodeAttach (NodeInterface& node, NodeInterface& parent)
174- {
175- D::Log ().template Append <NodeAttachEvent>(GetObjectId (node), GetObjectId (parent));
176- Engine ().OnNodeAttach (node, parent);
177- }
178-
179- static void OnNodeDetach (NodeInterface& node, NodeInterface& parent)
180- {
181- D::Log ().template Append <NodeDetachEvent>(GetObjectId (node), GetObjectId (parent));
182- Engine ().OnNodeDetach (node, parent);
183- }
184-
185- static void OnNodePulse (NodeInterface& node, TurnInterface& turn)
186- {
187- D::Log ().template Append <NodePulseEvent>(GetObjectId (node), turn.Id ());
188- Engine ().OnNodePulse (node, turn);
189- }
190-
191- static void OnNodeIdlePulse (NodeInterface& node, TurnInterface& turn)
192- {
193- D::Log ().template Append <NodeIdlePulseEvent>(GetObjectId (node), turn.Id ());
194- Engine ().OnNodeIdlePulse (node, turn);
195- }
196-
197- static void OnNodeShift (NodeInterface& node, NodeInterface& oldParent, NodeInterface& newParent, TurnInterface& turn)
198- {
199- D::Log ().template Append <NodeInvalidateEvent>(GetObjectId (node), GetObjectId (oldParent), GetObjectId (newParent), turn.Id ());
200- Engine ().OnNodeShift (node, oldParent, newParent, turn);
201- }
202-
203- static void OnTurnAdmissionStart (TurnInterface& turn)
204- {
205- D::Log ().template Append <TransactionBeginEvent>(turn.Id ());
206- Engine ().OnTurnAdmissionStart (turn);
207- }
208-
209- static void OnTurnAdmissionEnd (TurnInterface& turn)
210- {
211- Engine ().OnTurnAdmissionEnd (turn);
212- }
213-
214- static void OnTurnEnd (TurnInterface& turn)
215- {
216- D::Log ().template Append <TransactionEndEvent>(turn.Id ());
217- Engine ().OnTurnEnd (turn);
218- }
219-
220- static void OnTurnInputChange (NodeInterface& node, TurnInterface& turn)
221- {
222- D::Log ().template Append <InputNodeAdmissionEvent>(GetObjectId (node), turn.Id ());
223- Engine ().OnTurnInputChange (node, turn);
224- }
225-
226- static void OnTurnPropagate (TurnInterface& turn)
227- {
228- Engine ().OnTurnPropagate (turn);
229- }
230-
231- template <typename F>
232- static bool TryMerge (F&& f)
233- {
234- return Engine ().TryMerge (std::forward<F>(f));
235- }
236- };
237-
23849// //////////////////////////////////////////////////////////////////////////////////////
23950// / Domain
24051// //////////////////////////////////////////////////////////////////////////////////////
@@ -249,9 +60,6 @@ struct DomainPolicy
24960 using Log = TLog;
25061};
25162
252- using TurnIdT = uint;
253- using TurnFlagsT = uint;
254-
25563template <typename D, typename TPolicy>
25664class DomainBase
25765{
0 commit comments