Esempio n. 1
0
 /// <summary>
 /// Releases the resource held under this resource request back into the resource pool.
 /// </summary>
 /// <param name="resourceRequest">The resource request under which the resource has previously
 /// been acquired.</param>
 public void Release(IResourceRequest resourceRequest)
 {
     if (resourceRequest.ResourceObtained != null)
     {
         if (s_diagnostics)
         {
             string fromWhom = resourceRequest.ToString();
             if (resourceRequest.ResourceObtained != null)
             {
                 fromWhom = resourceRequest.ResourceObtained.Name;
             }
             _Debug.WriteLine(Name + " servicing request to release " + resourceRequest.QuantityDesired + " units of " + fromWhom);
         }
         IResource resourceReleased = resourceRequest.ResourceObtained;
         resourceRequest.ResourceObtained?.Release(resourceRequest);
         resourceRequest.Status = RequestStatus.Free;
         ResourceReleased?.Invoke(resourceRequest, resourceReleased);
         while (m_waiters.Count > 0)
         {
             IDetachableEventController dec = (IDetachableEventController)m_waiters[0];
             m_waiters.RemoveAt(0);
             if (dec.IsWaiting())
             {
                 dec.Resume();                    // We might be releasing all resources as a part of an abort.
             }
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Unreserves a quantity of resource from this pool that was previously reserved under the provided
 /// resource request.
 /// </summary>
 /// <param name="resourceRequest">The resource request under which some resource was previously reserved.</param>
 public void Unreserve(IResourceRequest resourceRequest)
 {
     if (s_diagnostics)
     {
         _Debug.WriteLine(Name + " servicing request to unreserve " + resourceRequest.QuantityDesired + " units of " + resourceRequest);
     }
     if (resourceRequest.ResourceObtained != null)
     {
         resourceRequest.ResourceObtained.Unreserve(resourceRequest);
         resourceRequest.Status = RequestStatus.Free;
     }
     while (m_waiters.Count > 0)
     {
         IDetachableEventController dec = (IDetachableEventController)m_waiters[0];
         m_waiters.RemoveAt(0);
         if (dec.IsWaiting())
         {
             dec.Resume();                                    // We might be releasing all resources as a part of an abort.
         }
     }
 }