Skip to content

Commit

Permalink
vcsim: lock ViewManager in RegisterObject callbacks
Browse files Browse the repository at this point in the history
ViewManager updates itself when objects are added to and removed from inventory.
These callbacks need to lock the ViewManager when making these changes.
  • Loading branch information
dougm committed Oct 7, 2024
1 parent 131e69e commit 5a9567f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions simulator/view_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,18 @@ func (v *ContainerView) find(root mo.Reference, ref types.ManagedObjectReference
func (v *ContainerView) PutObject(obj mo.Reference) {
ref := obj.Reference()

if v.include(ref) && v.find(v.root, ref, types.NewBool(false)) {
SpoofContext().Update(v, []types.PropertyChange{{Name: "view", Val: append(v.View, ref)}})
}
ctx := SpoofContext()
ctx.WithLock(v, func() {
if v.include(ref) && v.find(v.root, ref, types.NewBool(false)) {
ctx.Update(v, []types.PropertyChange{{Name: "view", Val: append(v.View, ref)}})
}
})
}

func (v *ContainerView) RemoveObject(ctx *Context, obj types.ManagedObjectReference) {
ctx.Map.RemoveReference(ctx, v, &v.View, obj)
ctx.WithLock(v, func() {
ctx.Map.RemoveReference(ctx, v, &v.View, obj)
})
}

func (*ContainerView) UpdateObject(*Context, mo.Reference, []types.PropertyChange) {}
Expand Down

0 comments on commit 5a9567f

Please sign in to comment.