diff --git a/OpenSim/Framework/ExpiringKey.cs b/OpenSim/Framework/ExpiringKey.cs index a322431552..f9261b642d 100644 --- a/OpenSim/Framework/ExpiringKey.cs +++ b/OpenSim/Framework/ExpiringKey.cs @@ -28,6 +28,7 @@ using System; using System.Threading; using System.Collections.Generic; using Timer = System.Threading.Timer ; +using System.Runtime.InteropServices; namespace OpenSim.Framework { @@ -168,6 +169,28 @@ namespace OpenSim.Framework finally { m_rwLock.ExitWriteLock(); } } + public bool AddOrUpdate(Tkey1 key, int expireMS) + { + int now; + if (expireMS > 0) + { + expireMS = (expireMS > m_expire) ? expireMS : m_expire; + now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS; + } + else + now = int.MinValue; + + m_rwLock.EnterWriteLock(); + try + { + ref int entry = ref CollectionsMarshal.GetValueRefOrAddDefault(m_dictionary, key, out bool exists); + entry = now; + CheckTimer(); + return exists; + } + finally { m_rwLock.ExitWriteLock(); } + } + public bool Remove(Tkey1 key) { m_rwLock.EnterWriteLock();