Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
burrow
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hang Yu
burrow
Commits
b51438b9
Unverified
Commit
b51438b9
authored
7 years ago
by
Silas Davis
Browse files
Options
Downloads
Patches
Plain Diff
Use RWMutex and lock it for poll reads to avoid concurrent read-write
parent
9d95e7f3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
event/event_cache.go
+4
-2
4 additions, 2 deletions
event/event_cache.go
with
4 additions
and
2 deletions
event/event_cache.go
+
4
−
2
View file @
b51438b9
...
@@ -59,7 +59,7 @@ func (this *EventCache) poll() []interface{} {
...
@@ -59,7 +59,7 @@ func (this *EventCache) poll() []interface{} {
// Catches events that callers subscribe to and adds them to an array ready to be polled.
// Catches events that callers subscribe to and adds them to an array ready to be polled.
type
EventSubscriptions
struct
{
type
EventSubscriptions
struct
{
mtx
*
sync
.
Mutex
mtx
*
sync
.
RW
Mutex
eventEmitter
EventEmitter
eventEmitter
EventEmitter
subs
map
[
string
]
*
EventCache
subs
map
[
string
]
*
EventCache
reap
bool
reap
bool
...
@@ -67,7 +67,7 @@ type EventSubscriptions struct {
...
@@ -67,7 +67,7 @@ type EventSubscriptions struct {
func
NewEventSubscriptions
(
eventEmitter
EventEmitter
)
*
EventSubscriptions
{
func
NewEventSubscriptions
(
eventEmitter
EventEmitter
)
*
EventSubscriptions
{
es
:=
&
EventSubscriptions
{
es
:=
&
EventSubscriptions
{
mtx
:
&
sync
.
Mutex
{},
mtx
:
&
sync
.
RW
Mutex
{},
eventEmitter
:
eventEmitter
,
eventEmitter
:
eventEmitter
,
subs
:
make
(
map
[
string
]
*
EventCache
),
subs
:
make
(
map
[
string
]
*
EventCache
),
reap
:
true
,
reap
:
true
,
...
@@ -121,6 +121,8 @@ func (this *EventSubscriptions) Add(eventId string) (string, error) {
...
@@ -121,6 +121,8 @@ func (this *EventSubscriptions) Add(eventId string) (string, error) {
}
}
func
(
this
*
EventSubscriptions
)
Poll
(
subId
string
)
([]
interface
{},
error
)
{
func
(
this
*
EventSubscriptions
)
Poll
(
subId
string
)
([]
interface
{},
error
)
{
this
.
mtx
.
RLock
()
defer
this
.
mtx
.
RUnlock
()
sub
,
ok
:=
this
.
subs
[
subId
]
sub
,
ok
:=
this
.
subs
[
subId
]
if
!
ok
{
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"Subscription not active. ID: "
+
subId
)
return
nil
,
fmt
.
Errorf
(
"Subscription not active. ID: "
+
subId
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment