Guard concurrent access to _outbound

This commit is contained in:
Tony Garnock-Jones 2023-10-28 13:52:27 +02:00
parent cb3fd44529
commit 85c106b6ca
1 changed files with 17 additions and 7 deletions

View File

@ -105,16 +105,22 @@ public class Actor implements Executor {
} }
} }
public void _injectOutbound(Long handle, Ref peer) { void _injectOutbound(Long handle, Ref peer) {
_outbound.put(handle, peer); synchronized (_outbound) {
_outbound.put(handle, peer);
}
} }
public Ref _lookupOutbound(Long handle) { Ref _lookupOutbound(Long handle) {
return _outbound.get(handle); synchronized (_outbound) {
return _outbound.get(handle);
}
} }
public Ref _extractOutbound(Long handle) { Ref _extractOutbound(Long handle) {
return _outbound.remove(handle); synchronized (_outbound) {
return _outbound.remove(handle);
}
} }
public String toString() { public String toString() {
@ -168,7 +174,11 @@ public class Actor implements Executor {
} else { } else {
log().log(Level.SEVERE, "Actor terminated with error", reason); log().log(Level.SEVERE, "Actor terminated with error", reason);
} }
Turn._forActor(this, t -> _outbound.forEach(t::_retract_)); Turn._forActor(this, t -> {
synchronized(_outbound) {
_outbound.forEach(t::_retract_);
}
});
_releaseCount(); _releaseCount();
} }
} }