// Must be called under ThisLock. Doesn't validate the InstanceOwner. private InstanceNormalEvent GetOwnerEventHelper(InstancePersistenceEvent persistenceEvent, InstanceOwner owner) { if (!owner.Events.TryGetValue(persistenceEvent.Name, out InstanceNormalEvent normal)) { normal = new InstanceNormalEvent(persistenceEvent); owner.Events.Add(persistenceEvent.Name, normal); } return(normal); }
internal void PendHandleToEvent(InstanceHandle handle, InstancePersistenceEvent persistenceEvent, InstanceOwner owner) { lock (ThisLock) { Fx.Assert(_owners.ContainsKey(owner.InstanceOwnerId), "InstanceHandle called PendHandleToEvent on wrong InstanceStore!!"); Fx.Assert(object.ReferenceEquals(_owners[owner.InstanceOwnerId].Target, owner), "How did multiple of the same owner become simultaneously active?"); InstanceNormalEvent normal = GetOwnerEventHelper(persistenceEvent, owner); Fx.Assert(!normal.PendingHandles.Contains(handle), "Should not have already pended the handle."); Fx.Assert(!normal.BoundHandles.Contains(handle), "Should not be able to pend an already-bound handle."); normal.PendingHandles.Add(handle); } }
internal InstancePersistenceEvent AddHandleToEvent(InstanceHandle handle, InstancePersistenceEvent persistenceEvent, InstanceOwner owner) { lock (ThisLock) { Fx.Assert(_owners.ContainsKey(owner.InstanceOwnerId), "InstanceHandle called AddHandleToEvent on wrong InstanceStore!!"); Fx.Assert(object.ReferenceEquals(_owners[owner.InstanceOwnerId].Target, owner), "How did multiple instances of the same owner become simultaneously active?"); InstanceNormalEvent normal = GetOwnerEventHelper(persistenceEvent, owner); Fx.Assert(normal.PendingHandles.Contains(handle), "Should have already pended the handle."); Fx.Assert(!normal.BoundHandles.Contains(handle), "Should not be able to add a handle to an event twice."); normal.BoundHandles.Add(handle); normal.PendingHandles.Remove(handle); return(normal.IsSignaled ? normal : null); } }