Пример #1
0
 public void Remove(ObjectMonitor monitor)
 {
     lock (m_sync)
     {
         if (Object.ReferenceEquals(m_first, monitor))
         {
             if (Object.ReferenceEquals(m_last, monitor))
             {
                 m_first = null;
                 m_last  = null;
             }
             else
             {
                 m_first = m_first.m_next;
             }
         }
         else if (Object.ReferenceEquals(m_first, monitor))
         {
             m_last = m_last.m_previous;
         }
         monitor.Dispose();
         m_listLength--;
         m_listChangeIndex++;
     }
 }
Пример #2
0
 internal void Setup(ObjectMonitor previous, object target)
 {
     if (previous != null)
     {
         previous.m_next = this;
     }
     m_previous  = previous;
     m_reference = new WeakReference(target);
     if (target is IAvailability)
     {
         (target as IAvailability).Disposing += ObjectMonitor_Disposing;
         (target as IAvailability).Disposed  += ObjectMonitor_Disposed;
     }
 }
Пример #3
0
        internal void Dispose()
        {
            this.OnMonitorDispose();
            m_state     = State.MonitorDisposed;
            m_reference = null;
            if (m_previous != null)
            {
                m_previous.m_next = m_next;
            }
            if (m_next != null)
            {
                m_next.m_previous = m_previous;
            }
            m_previous = null;
            m_next     = null;

            this.StateChanged?.Invoke(this, EventArgs.Empty);
        }
Пример #4
0
 public ObjectMonitor[] CreateSnapshotListIfChanged(ref long lastKnownChangeIndex)
 {
     lock (m_sync)
     {
         if (m_listChangeIndex != lastKnownChangeIndex)
         {
             lastKnownChangeIndex = m_listChangeIndex;
             var array = new ObjectMonitor[m_listLength];
             var next  = m_first;
             for (int i = 0; i < m_listLength; i++)
             {
                 array[i] = next;
                 next     = next.m_next;
             }
             return(array);
         }
         else
         {
             return(null);
         }
     }
 }
Пример #5
0
 public ObjectMonitor CreateObjectMonitor(object target)
 {
     if (target == null)
     {
         throw new ArgumentNullException("target");
     }
     lock (m_sync)
     {
         if (m_first == null)
         {
             m_first = new ObjectMonitor(null, target);
             m_last  = m_first;
         }
         else
         {
             m_last = new ObjectMonitor(m_last, target);
         }
         m_last.PostCreate(target);
         m_listLength++;
         m_listChangeIndex++;
         return(m_last);
     }
 }
Пример #6
0
 protected ObjectMonitor()
 {
     m_previous  = null;
     m_reference = null;
 }
Пример #7
0
 internal ObjectMonitor(ObjectMonitor previous, object target)
 {
     this.Setup(previous, target);
 }