forked from snakster/cpp.react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathELMEngine.h
More file actions
116 lines (84 loc) · 3.59 KB
/
ELMEngine.h
File metadata and controls
116 lines (84 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright Sebastian Jeckel 2014.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#pragma once
#include "react/detail/Defs.h"
#include <atomic>
#include <set>
#include "tbb/task_group.h"
#include "tbb/spin_mutex.h"
#include "react/common/Containers.h"
#include "react/common/Types.h"
#include "react/detail/EngineBase.h"
#include "react/detail/ReactiveDomain.h"
/***************************************/ REACT_IMPL_BEGIN /**************************************/
namespace elm {
using std::atomic;
using std::set;
using tbb::task_group;
using tbb::spin_mutex;
///////////////////////////////////////////////////////////////////////////////////////////////////
/// Turn
///////////////////////////////////////////////////////////////////////////////////////////////////
class Turn : public TurnBase
{
public:
Turn(TurnIdT id, TurnFlagsT flags);
};
///////////////////////////////////////////////////////////////////////////////////////////////////
/// Node
///////////////////////////////////////////////////////////////////////////////////////////////////
class Node : public IReactiveNode
{
public:
using ShiftMutexT = spin_mutex;
Node();
ShiftMutexT ShiftMutex;
NodeVector<Node> Successors;
atomic<int16_t> Counter;
atomic<bool> ShouldUpdate;
TurnIdT LastTurnId;
};
///////////////////////////////////////////////////////////////////////////////////////////////////
/// Engine
///////////////////////////////////////////////////////////////////////////////////////////////////
template <typename TTurn>
class EngineBase : public IReactiveEngine<Node,TTurn>
{
public:
using NodeShiftMutexT = Node::ShiftMutexT;
using NodeSetT = set<Node*>;
void OnNodeCreate(Node& node);
void OnNodeDestroy(Node& node);
void OnNodeAttach(Node& node, Node& parent);
void OnNodeDetach(Node& node, Node& parent);
void OnTurnInputChange(Node& node, TTurn& turn);
void OnTurnPropagate(TTurn& turn);
void OnNodePulse(Node& node, TTurn& turn);
void OnNodeIdlePulse(Node& node, TTurn& turn);
void OnDynamicNodeAttach(Node& node, Node& parent, TTurn& turn);
void OnDynamicNodeDetach(Node& node, Node& parent, TTurn& turn);
private:
void processChild(Node& node, bool update, TTurn& turn);
void nudgeChildren(Node& parent, bool update, TTurn& turn);
task_group tasks_;
NodeSetT inputNodes_;
};
class BasicEngine : public EngineBase<Turn> {};
class QueuingEngine : public DefaultQueuingEngine<EngineBase,Turn> {};
} // ~namespace elm
/****************************************/ REACT_IMPL_END /***************************************/
/*****************************************/ REACT_BEGIN /*****************************************/
struct parallel;
struct parallel_queue;
template <typename TMode>
class ELMEngine;
template <> class ELMEngine<parallel> : public REACT_IMPL::elm::BasicEngine {};
template <> class ELMEngine<parallel_queue> : public REACT_IMPL::elm::QueuingEngine {};
/******************************************/ REACT_END /******************************************/
/***************************************/ REACT_IMPL_BEGIN /**************************************/
template <typename> struct EnableParallelUpdating;
template <> struct EnableParallelUpdating<ELMEngine<parallel>> : std::true_type {};
template <> struct EnableParallelUpdating<ELMEngine<parallel_queue>> : std::true_type {};
/****************************************/ REACT_IMPL_END /***************************************/