Beispiel #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);
     }
 }
Beispiel #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);
     }
 }
Beispiel #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);
     }
 }
Beispiel #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);
        }