Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
5a2afc57
Commit
5a2afc57
authored
Jul 05, 2014
by
zelig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix reactor engine main loop blocked to wait if drained
parent
d4300c40
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
8 deletions
+14
-8
reactor.go
ethreact/reactor.go
+14
-8
No files found.
ethreact/reactor.go
View file @
5a2afc57
...
@@ -28,7 +28,7 @@ func (e *EventHandler) Post(event Event) {
...
@@ -28,7 +28,7 @@ func (e *EventHandler) Post(event Event) {
select
{
select
{
case
ch
<-
event
:
case
ch
<-
event
:
default
:
default
:
logger
.
Warn
ln
(
"subscribing channel %d to event %s blocked. skipping
"
,
i
,
event
.
Name
)
logger
.
Warn
f
(
"subscribing channel %d to event %s blocked. skipping
\n
"
,
i
,
event
.
Name
)
}
}
}
}
}
}
...
@@ -69,7 +69,7 @@ type ReactorEngine struct {
...
@@ -69,7 +69,7 @@ type ReactorEngine struct {
quit
chan
bool
quit
chan
bool
shutdownChannel
chan
bool
shutdownChannel
chan
bool
running
bool
running
bool
drained
bool
drained
chan
bool
}
}
func
New
()
*
ReactorEngine
{
func
New
()
*
ReactorEngine
{
...
@@ -77,6 +77,7 @@ func New() *ReactorEngine {
...
@@ -77,6 +77,7 @@ func New() *ReactorEngine {
eventHandlers
:
make
(
map
[
string
]
*
EventHandler
),
eventHandlers
:
make
(
map
[
string
]
*
EventHandler
),
eventChannel
:
make
(
chan
Event
),
eventChannel
:
make
(
chan
Event
),
quit
:
make
(
chan
bool
,
1
),
quit
:
make
(
chan
bool
,
1
),
drained
:
make
(
chan
bool
,
1
),
shutdownChannel
:
make
(
chan
bool
,
1
),
shutdownChannel
:
make
(
chan
bool
,
1
),
}
}
}
}
...
@@ -94,8 +95,9 @@ func (reactor *ReactorEngine) Start() {
...
@@ -94,8 +95,9 @@ func (reactor *ReactorEngine) Start() {
case
event
:=
<-
reactor
.
eventChannel
:
case
event
:=
<-
reactor
.
eventChannel
:
// needs to be called syncronously to keep order of events
// needs to be called syncronously to keep order of events
reactor
.
dispatch
(
event
)
reactor
.
dispatch
(
event
)
case
reactor
.
drained
<-
true
:
default
:
default
:
reactor
.
drained
=
true
reactor
.
drained
<-
true
// blocking till message is coming in
}
}
}
}
reactor
.
lock
.
Lock
()
reactor
.
lock
.
Lock
()
...
@@ -113,14 +115,16 @@ func (reactor *ReactorEngine) Stop() {
...
@@ -113,14 +115,16 @@ func (reactor *ReactorEngine) Stop() {
reactor
.
lock
.
RLock
()
reactor
.
lock
.
RLock
()
if
reactor
.
running
{
if
reactor
.
running
{
reactor
.
quit
<-
true
reactor
.
quit
<-
true
select
{
case
<-
reactor
.
drained
:
}
}
}
reactor
.
lock
.
RUnlock
()
reactor
.
lock
.
RUnlock
()
<-
reactor
.
shutdownChannel
<-
reactor
.
shutdownChannel
}
}
func
(
reactor
*
ReactorEngine
)
Flush
()
{
func
(
reactor
*
ReactorEngine
)
Flush
()
{
for
!
reactor
.
drained
{
<-
reactor
.
drained
}
}
}
// Subscribe a channel to the specified event
// Subscribe a channel to the specified event
...
@@ -136,7 +140,7 @@ func (reactor *ReactorEngine) Subscribe(event string, eventChannel chan Event) {
...
@@ -136,7 +140,7 @@ func (reactor *ReactorEngine) Subscribe(event string, eventChannel chan Event) {
}
}
// Add the events channel to reactor event handler
// Add the events channel to reactor event handler
eventHandler
.
Add
(
eventChannel
)
eventHandler
.
Add
(
eventChannel
)
logger
.
Debug
ln
(
"added new subscription to %s"
,
event
)
logger
.
Debug
f
(
"added new subscription to %s"
,
event
)
}
}
func
(
reactor
*
ReactorEngine
)
Unsubscribe
(
event
string
,
eventChannel
chan
Event
)
{
func
(
reactor
*
ReactorEngine
)
Unsubscribe
(
event
string
,
eventChannel
chan
Event
)
{
...
@@ -149,7 +153,7 @@ func (reactor *ReactorEngine) Unsubscribe(event string, eventChannel chan Event)
...
@@ -149,7 +153,7 @@ func (reactor *ReactorEngine) Unsubscribe(event string, eventChannel chan Event)
if
len
==
0
{
if
len
==
0
{
reactor
.
eventHandlers
[
event
]
=
nil
reactor
.
eventHandlers
[
event
]
=
nil
}
}
logger
.
Debug
ln
(
"removed subscription to %s"
,
event
)
logger
.
Debug
f
(
"removed subscription to %s"
,
event
)
}
}
}
}
...
@@ -158,8 +162,10 @@ func (reactor *ReactorEngine) Post(event string, resource interface{}) {
...
@@ -158,8 +162,10 @@ func (reactor *ReactorEngine) Post(event string, resource interface{}) {
defer
reactor
.
lock
.
Unlock
()
defer
reactor
.
lock
.
Unlock
()
if
reactor
.
running
{
if
reactor
.
running
{
reactor
.
drained
=
false
reactor
.
eventChannel
<-
Event
{
Resource
:
resource
,
Name
:
event
}
reactor
.
eventChannel
<-
Event
{
Resource
:
resource
,
Name
:
event
}
select
{
case
<-
reactor
.
drained
:
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment