public void DeleteLinkWithResource(int threadId, SafeResource resource) { lock (_syncRoot) { var threadNode = GetThreadNode(threadId); var resourceNode = GetResourceNode(resource); threadNode.Links.Remove(resourceNode); resourceNode.Links.Remove(threadNode); } }
public void AddRequestToResource(int threadId, SafeResource resource) { lock (_syncRoot) { var threadNode = GetThreadNode(threadId); var resourceNode = GetResourceNode(resource); threadNode.Links.AddLast(resourceNode); CheckCycle(resourceNode); } }
public void ApplyRequestToResource(int threadId, SafeResource resource) { lock (_syncRoot) { var threadNode = GetThreadNode(threadId); var resourceNode = GetResourceNode(resource); if (!threadNode.Links.Remove(resourceNode)) { throw new ApplicationException("Resource link not found"); } resourceNode.Links.AddLast(threadNode); CheckCycle(threadNode); } }
private Node GetResourceNode(SafeResource resource) { var resourceNode = _resourceNodes.FirstOrDefault(n => n.Resource == resource); if (resourceNode == null) { resourceNode = new Node { Resource = resource, ThreadId = -1 }; _resourceNodes.Add(resourceNode); } return(resourceNode); }