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
dc11b5c5
Commit
dc11b5c5
authored
Jul 14, 2014
by
zelig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix reactor channel blocking
parent
5c03adbd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
26 deletions
+27
-26
reactor.go
ethreact/reactor.go
+27
-26
No files found.
ethreact/reactor.go
View file @
dc11b5c5
...
...
@@ -7,6 +7,10 @@ import (
var
logger
=
ethlog
.
NewLogger
(
"REACTOR"
)
const
(
eventBufferSize
int
=
10
)
type
EventHandler
struct
{
lock
sync
.
RWMutex
name
string
...
...
@@ -21,7 +25,7 @@ func (e *EventHandler) Post(event Event) {
// if we want to preserve order pushing to subscibed channels
// dispatching should be syncrounous
// this means if subscribed event channel is blocked
(closed or has fixed capacity)
// this means if subscribed event channel is blocked
// the reactor dispatch will be blocked, so we need to mitigate by skipping
// rogue blocking subscribers
for
i
,
ch
:=
range
e
.
chans
{
...
...
@@ -63,22 +67,20 @@ type Event struct {
// The reactor basic engine. Acts as bridge
// between the events and the subscribers/posters
type
ReactorEngine
struct
{
lock
sync
.
RWMutex
eventChannel
chan
Event
eventHandlers
map
[
string
]
*
EventHandler
quit
chan
bool
shutdownChannel
chan
bool
running
bool
drained
chan
bool
lock
sync
.
RWMutex
eventChannel
chan
Event
eventHandlers
map
[
string
]
*
EventHandler
quit
chan
chan
error
running
bool
drained
chan
bool
}
func
New
()
*
ReactorEngine
{
return
&
ReactorEngine
{
eventHandlers
:
make
(
map
[
string
]
*
EventHandler
),
eventChannel
:
make
(
chan
Event
),
quit
:
make
(
chan
bool
,
1
),
drained
:
make
(
chan
bool
,
1
),
shutdownChannel
:
make
(
chan
bool
,
1
),
eventHandlers
:
make
(
map
[
string
]
*
EventHandler
),
eventChannel
:
make
(
chan
Event
,
eventBufferSize
),
quit
:
make
(
chan
chan
error
,
1
),
drained
:
make
(
chan
bool
,
1
),
}
}
...
...
@@ -87,24 +89,22 @@ func (reactor *ReactorEngine) Start() {
defer
reactor
.
lock
.
Unlock
()
if
!
reactor
.
running
{
go
func
()
{
out
:
for
{
select
{
case
<-
reactor
.
quit
:
break
out
case
status
:=
<-
reactor
.
quit
:
reactor
.
lock
.
Lock
()
defer
reactor
.
lock
.
Unlock
()
reactor
.
running
=
false
logger
.
Infoln
(
"stopped"
)
status
<-
nil
return
case
event
:=
<-
reactor
.
eventChannel
:
// needs to be called syncronously to keep order of events
reactor
.
dispatch
(
event
)
// case reactor.drained <- true:
default
:
reactor
.
drained
<-
true
// blocking till message is coming in
}
}
reactor
.
lock
.
Lock
()
defer
reactor
.
lock
.
Unlock
()
reactor
.
running
=
false
logger
.
Infoln
(
"stopped"
)
close
(
reactor
.
shutdownChannel
)
}()
reactor
.
running
=
true
logger
.
Infoln
(
"started"
)
...
...
@@ -112,15 +112,15 @@ func (reactor *ReactorEngine) Start() {
}
func
(
reactor
*
ReactorEngine
)
Stop
()
{
reactor
.
lock
.
RLock
()
if
reactor
.
running
{
reactor
.
quit
<-
true
status
:=
make
(
chan
error
)
reactor
.
quit
<-
status
select
{
case
<-
reactor
.
drained
:
default
:
}
<-
status
}
reactor
.
lock
.
RUnlock
()
<-
reactor
.
shutdownChannel
}
func
(
reactor
*
ReactorEngine
)
Flush
()
{
...
...
@@ -165,6 +165,7 @@ func (reactor *ReactorEngine) Post(event string, resource interface{}) {
reactor
.
eventChannel
<-
Event
{
Resource
:
resource
,
Name
:
event
}
select
{
case
<-
reactor
.
drained
:
default
:
}
}
}
...
...
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