Exemplo n.º 1
0
        //  Cycles through the table periodically and cleans up expired entries.
        //
        private static void CleanupIdentities(Object state)
        {
            // FUTURE:: come up with a better way to do this
            BCLDebug.Assert(
                Thread.GetDomain().RemotingData.IDTableLock.IsWriterLockHeld,
                "ID Table being cleaned up without taking a lock!");

            IDictionaryEnumerator e          = URITable.GetEnumerator();
            ArrayList             removeList = new ArrayList();

            while (e.MoveNext())
            {
                Object        o  = e.Value;
                WeakReference wr = o as WeakReference;
                if ((null != wr) && (null == wr.Target))
                {
                    removeList.Add(e.Key);
                }
            }

            foreach (String key in removeList)
            {
                URITable.Remove(key);
            }
        }
Exemplo n.º 2
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static void RemoveIdentity(String uri, bool bResetURI)
        {
            Contract.Assert(uri != null, "Null URI");
            BCLDebug.Trace("REMOTE",
                           "IdentityHolder.WeakenIdentity ", uri, " for context ", Thread.CurrentContext);

            Identity id;
            String   uriKey = MakeURIKey(uri);
            // We need to guarantee that finally is not interrupted so that the lock is released.
            // TableLock has a long path without reliability contract.  To avoid adding contract on
            // the path, we will use ReaderWriterLock directly.
            ReaderWriterLock rwlock         = TableLock;
            bool             takeAndRelease = !rwlock.IsWriterLockHeld;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                if (takeAndRelease)
                {
                    rwlock.AcquireWriterLock(INFINITE);
                }

                Object        oRef = URITable[uriKey];
                WeakReference wr   = oRef as WeakReference;
                if (null != wr)
                {
                    id        = (Identity)wr.Target;
                    wr.Target = null;
                }
                else
                {
                    id = (Identity)oRef;
                    if (id != null)
                    {
                        ((ServerIdentity)id).ResetHandle();
                    }
                }

                if (id != null)
                {
                    URITable.Remove(uriKey);
                    // Mark the ID as not present in the ID Table
                    // This will clear its URI & objRef fields
                    id.ResetInIDTable(bResetURI);
                }
            }
            finally
            {
                if (takeAndRelease && rwlock.IsWriterLockHeld)
                {
                    rwlock.ReleaseWriterLock();
                }
            }
        } // RemoveIdentity
        private static void CleanupIdentities(object state)
        {
            IDictionaryEnumerator enumerator = URITable.GetEnumerator();
            ArrayList             list       = new ArrayList();

            while (enumerator.MoveNext())
            {
                WeakReference reference = enumerator.Value as WeakReference;
                if ((reference != null) && (reference.Target == null))
                {
                    list.Add(enumerator.Key);
                }
            }
            foreach (string str in list)
            {
                URITable.Remove(str);
            }
        }
        internal static void RemoveIdentity(string uri, bool bResetURI)
        {
            string           key       = MakeURIKey(uri);
            ReaderWriterLock tableLock = TableLock;
            bool             flag      = !tableLock.IsWriterLockHeld;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                Identity target;
                if (flag)
                {
                    tableLock.AcquireWriterLock(0x7fffffff);
                }
                object        obj2      = URITable[key];
                WeakReference reference = obj2 as WeakReference;
                if (reference != null)
                {
                    target           = (Identity)reference.Target;
                    reference.Target = null;
                }
                else
                {
                    target = (Identity)obj2;
                    if (target != null)
                    {
                        ((ServerIdentity)target).ResetHandle();
                    }
                }
                if (target != null)
                {
                    URITable.Remove(key);
                    target.ResetInIDTable(bResetURI);
                }
            }
            finally
            {
                if (flag && tableLock.IsWriterLockHeld)
                {
                    tableLock.ReleaseWriterLock();
                }
            }
        }
Exemplo n.º 5
0
        internal static void RemoveIdentity(String uri, bool bResetURI)
        {
            BCLDebug.Assert(uri != null, "Null URI");
            BCLDebug.Trace("REMOTE",
                           "IdentityHolder.WeakenIdentity ", uri, " for context ", Thread.CurrentContext);

            Identity id;
            String   uriKey = MakeURIKey(uri);

            try
            {
                TableLock.AcquireWriterLock(INFINITE);
                Object        oRef = URITable[uriKey];
                WeakReference wr   = oRef as WeakReference;
                if (null != wr)
                {
                    id        = (Identity)wr.Target;
                    wr.Target = null;
                }
                else
                {
                    id = (Identity)oRef;
                }

                if (id != null)
                {
                    URITable.Remove(uriKey);
                    // Mark the ID as not present in the ID Table
                    // This will clear its URI & objRef fields
                    id.ResetInIDTable(bResetURI);
                }
            }
            finally
            {
                TableLock.ReleaseWriterLock();
            }
        } // RemoveIdentity