Make FlowOperationsProcessor thread-safe with synchronized modifier
Different threads could call run(), satisfy() and fail() method. Each of the methods reads/writes multiple fields during the method call. These method calls need to be synchronized to gurantee to see the latest value. Change-Id: Ic252b56e0902170d7e0fdb83f96f0fb2e55ec56b
Showing
1 changed file
with
3 additions
and
3 deletions
... | @@ -609,7 +609,7 @@ public class FlowRuleManager | ... | @@ -609,7 +609,7 @@ public class FlowRuleManager |
609 | } | 609 | } |
610 | 610 | ||
611 | @Override | 611 | @Override |
612 | - public void run() { | 612 | + public synchronized void run() { |
613 | if (stages.size() > 0) { | 613 | if (stages.size() > 0) { |
614 | process(stages.remove(0)); | 614 | process(stages.remove(0)); |
615 | } else if (!hasFailed.get() && context != null) { | 615 | } else if (!hasFailed.get() && context != null) { |
... | @@ -654,7 +654,7 @@ public class FlowRuleManager | ... | @@ -654,7 +654,7 @@ public class FlowRuleManager |
654 | } | 654 | } |
655 | } | 655 | } |
656 | 656 | ||
657 | - void satisfy(DeviceId devId) { | 657 | + synchronized void satisfy(DeviceId devId) { |
658 | pendingDevices.remove(devId); | 658 | pendingDevices.remove(devId); |
659 | if (pendingDevices.isEmpty()) { | 659 | if (pendingDevices.isEmpty()) { |
660 | operationsService.execute(this); | 660 | operationsService.execute(this); |
... | @@ -663,7 +663,7 @@ public class FlowRuleManager | ... | @@ -663,7 +663,7 @@ public class FlowRuleManager |
663 | 663 | ||
664 | 664 | ||
665 | 665 | ||
666 | - void fail(DeviceId devId, Set<? extends FlowRule> failures) { | 666 | + synchronized void fail(DeviceId devId, Set<? extends FlowRule> failures) { |
667 | hasFailed.set(true); | 667 | hasFailed.set(true); |
668 | pendingDevices.remove(devId); | 668 | pendingDevices.remove(devId); |
669 | if (pendingDevices.isEmpty()) { | 669 | if (pendingDevices.isEmpty()) { | ... | ... |
-
Please register or login to post a comment