Reset ArrayPortalToken when Detach is called

When `ArrayPortalToken::Detach` was called, the contained `Token` was
detached, but `ArrayPortal` being wrapped might also be holding its own
portal that it is decorating. To ensure that any dependent portals are
also detached, `ArrayPortalToken::Detach` resets itself.
This commit is contained in:
Kenneth Moreland 2020-03-09 16:24:23 -06:00
parent 53c17a6876
commit 75cb53d3ad
2 changed files with 17 additions and 1 deletions

@ -91,7 +91,14 @@ public:
///
/// This will open up the `ArrayHandle` for reading and/or writing.
///
VTKM_CONT void Detach() { this->Token->DetachFromAll(); }
VTKM_CONT void Detach()
{
this->Token->DetachFromAll();
// Reset this portal in case the superclass is holding other array portals with their own
// tokens. Detach is supposed to invalidate the array portal, so it is OK to do this.
*this = ArrayPortalToken<PortalType_>();
}
/// \brief Get the `Token` of the `ArrayPortal`.
///

@ -217,6 +217,15 @@ struct Test
// the concreteArray getting locked up.
CheckPortal(virtualArray.ReadPortal());
SetPortal(concreteArray.WritePortal());
// Make sure Detach also correctly unlocks the concrete array.
auto readPortal = virtualArray.ReadPortal();
readPortal.Detach();
concreteArray.WritePortal();
auto writePortal = virtualArray.WritePortal();
writePortal.Detach();
concreteArray.WritePortal();
}
void operator()()