示例#1
0
 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);
     }
 }
示例#2
0
 public void AddRequestToResource(int threadId, SafeResource resource)
 {
     lock (_syncRoot)
     {
         var threadNode   = GetThreadNode(threadId);
         var resourceNode = GetResourceNode(resource);
         threadNode.Links.AddLast(resourceNode);
         CheckCycle(resourceNode);
     }
 }
示例#3
0
 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);
     }
 }
示例#4
0
        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);
        }