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
10bbf265
Commit
10bbf265
authored
Oct 16, 2014
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event: make Unsubscribe idempotent
parent
dac4a8f1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
7 deletions
+16
-7
event.go
event/event.go
+16
-7
No files found.
event/event.go
View file @
10bbf265
...
...
@@ -124,14 +124,16 @@ func posdelete(slice []*muxsub, pos int) []*muxsub {
type
muxsub
struct
{
mux
*
TypeMux
mutex
sync
.
RW
Mutex
closeMu
sync
.
Mutex
closing
chan
struct
{}
closed
bool
// these two are the same channel. they are stored separately so
// postC can be set to nil without affecting the return value of
// Chan.
readC
<-
chan
interface
{}
postC
chan
<-
interface
{}
postMu
sync
.
RWMutex
readC
<-
chan
interface
{}
postC
chan
<-
interface
{}
}
func
newsub
(
mux
*
TypeMux
)
*
muxsub
{
...
...
@@ -154,18 +156,25 @@ func (s *muxsub) Unsubscribe() {
}
func
(
s
*
muxsub
)
closewait
()
{
s
.
closeMu
.
Lock
()
defer
s
.
closeMu
.
Unlock
()
if
s
.
closed
{
return
}
close
(
s
.
closing
)
s
.
mutex
.
Lock
()
s
.
closed
=
true
s
.
postMu
.
Lock
()
close
(
s
.
postC
)
s
.
postC
=
nil
s
.
mutex
.
Unlock
()
s
.
postMu
.
Unlock
()
}
func
(
s
*
muxsub
)
deliver
(
ev
interface
{})
{
s
.
mutex
.
RLock
()
s
.
postMu
.
RLock
()
select
{
case
s
.
postC
<-
ev
:
case
<-
s
.
closing
:
}
s
.
mutex
.
RUnlock
()
s
.
postMu
.
RUnlock
()
}
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