FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp.react/include/react/engine/PulsecountEngine.h at master · lineCode/cpp.react · GitHub
lineCode
/
cpp.react
Public
forked from
snakster/cpp.react
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp.react
/
include
/
react
/
engine
/
PulsecountEngine.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
147 lines (111 loc) · 4.2 KB
Breadcrumbs
cpp.react
/
include
/
react
/
engine
/
PulsecountEngine.h
Copy path
File metadata and controls
147 lines (111 loc) · 4.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//
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)
#
ifndef
REACT_DETAIL_ENGINE_PULSECOUNTENGINE_H_INCLUDED
#
define
REACT_DETAIL_ENGINE_PULSECOUNTENGINE_H_INCLUDED
#
pragma
once
#
include
"
react/detail/Defs.h
"
#
include
<
atomic
>
#
include
<
type_traits
>
#
include
<
vector
>
#
include
"
tbb/task_group.h
"
#
include
"
tbb/spin_rw_mutex.h
"
#
include
"
tbb/task.h
"
#
include
"
react/common/Containers.h
"
#
include
"
react/common/Types.h
"
#
include
"
react/detail/EngineBase.h
"
/*
*************************************
*/
REACT_IMPL_BEGIN
/*
************************************
*/
namespace
pulsecount
{
using
std::atomic;
using
std::vector;
using
tbb::task;
using
tbb::empty_task;
using
tbb::spin_rw_mutex;
using
tbb::task_list;
//
/////////////////////////////////////////////////////////////////////////////////////////////////
//
/ Turn
//
/////////////////////////////////////////////////////////////////////////////////////////////////
class
Turn
:
public
TurnBase
{
public:
Turn
(TurnIdT id, TransactionFlagsT flags);
};
//
/////////////////////////////////////////////////////////////////////////////////////////////////
//
/ Node
//
/////////////////////////////////////////////////////////////////////////////////////////////////
enum
class
ENodeMark
{
unmarked,
visited,
should_update
};
enum
class
ENodeState
{
unchanged,
changed,
dyn_defer,
dyn_repeat
};
class
Node
:
public
IReactiveNode
{
public:
using
ShiftMutexT = spin_rw_mutex;
inline
void
IncCounter
() { counter_.
fetch_add
(
1
, std::memory_order_relaxed); }
inline
bool
DecCounter
() {
return
counter_.
fetch_sub
(
1
, std::memory_order_relaxed) >
1
; }
inline
void
SetCounter
(
int
c) { counter_.
store
(c, std::memory_order_relaxed); }
inline
ENodeMark
Mark
()
const
{
return
mark_.
load
(std::memory_order_relaxed);
}
inline
void
SetMark
(ENodeMark mark)
{
mark_.
store
(mark, std::memory_order_relaxed);
}
inline
bool
ExchangeMark
(ENodeMark mark)
{
return
mark_.
exchange
(mark, std::memory_order_relaxed) != mark;
}
ShiftMutexT ShiftMutex;
NodeVector<Node> Successors;
ENodeState State = ENodeState::unchanged;
private:
atomic<
int
> counter_ {
0
};
atomic<ENodeMark> mark_ { ENodeMark::unmarked };
};
//
/////////////////////////////////////////////////////////////////////////////////////////////////
//
/ EngineBase
//
/////////////////////////////////////////////////////////////////////////////////////////////////
class
EngineBase
:
public
IReactiveEngine
<Node,Turn>
{
public:
using
NodeShiftMutexT = Node::ShiftMutexT;
using
NodeVectT = vector<Node*>;
void
OnNodeAttach
(Node& node, Node& parent);
void
OnNodeDetach
(Node& node, Node& parent);
void
OnInputChange
(Node& node, Turn& turn);
void
Propagate
(Turn& turn);
void
OnNodePulse
(Node& node, Turn& turn);
void
OnNodeIdlePulse
(Node& node, Turn& turn);
void
OnDynamicNodeAttach
(Node& node, Node& parent, Turn& turn);
void
OnDynamicNodeDetach
(Node& node, Node& parent, Turn& turn);
private:
NodeVectT changedInputs_;
empty_task& rootTask_ = *
new
(task::allocate_root()) empty_task;
task_list spawnList_;
};
}
//
~namespace pulsecount
/*
**************************************
*/
REACT_IMPL_END
/*
*************************************
*/
/*
***************************************
*/
REACT_BEGIN
/*
***************************************
*/
template
<
REACT_IMPL
::EPropagationMode>
class
PulsecountEngine
;
template
<>
class
PulsecountEngine
<
REACT_IMPL
::parallel_propagation> :
public
REACT_IMPL
::pulsecount::EngineBase
{};
/*
****************************************
*/
REACT_END
/*
****************************************
*/
/*
*************************************
*/
REACT_IMPL_BEGIN
/*
************************************
*/
template
<>
struct
NodeUpdateTimerEnabled
<PulsecountEngine<parallel_propagation>> : std::true_type {};
/*
**************************************
*/
REACT_IMPL_END
/*
*************************************
*/
#endif
//
REACT_DETAIL_ENGINE_PULSECOUNTENGINE_H_INCLUDED
Back
|
FazBrowse Home
|
New Git URL