summaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/table
diff options
context:
space:
mode:
authorCarl Baldwin <carl@ecbaldwin.net>2019-10-11 13:32:21 -0600
committerFUJITA Tomonori <fujita.tomonori@gmail.com>2019-10-15 20:21:18 +0900
commitbfb371d0c2f543c7dd5ee4afa112a6546c886ec2 (patch)
treed6de1ec637a26acdda26a5a2053625084bd3153b /internal/pkg/table
parent65929fe5245f715322286f683cbcf3d15699e8b4 (diff)
Avoid locking in cases that return immediately
This just defers the read lock over some of the code that doesn't inspect or modify any RoutingPolicy data. It allows the early returns to happen without ever taking the read lock.
Diffstat (limited to 'internal/pkg/table')
-rw-r--r--internal/pkg/table/policy.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/internal/pkg/table/policy.go b/internal/pkg/table/policy.go
index 3ced3b96..3395863d 100644
--- a/internal/pkg/table/policy.go
+++ b/internal/pkg/table/policy.go
@@ -3109,9 +3109,6 @@ type RoutingPolicy struct {
}
func (r *RoutingPolicy) ApplyPolicy(id string, dir PolicyDirection, before *Path, options *PolicyOptions) *Path {
- r.mu.RLock()
- defer r.mu.RUnlock()
-
if before == nil {
return nil
}
@@ -3121,6 +3118,10 @@ func (r *RoutingPolicy) ApplyPolicy(id string, dir PolicyDirection, before *Path
}
result := ROUTE_TYPE_NONE
after := before
+
+ r.mu.RLock()
+ defer r.mu.RUnlock()
+
for _, p := range r.getPolicy(id, dir) {
result, after = p.Apply(after, options)
if result != ROUTE_TYPE_NONE {