From 1b9cdbbe405e04f13393639630508a25eb005b23 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 17 Aug 2020 15:51:48 +0100 Subject: [PATCH] let expiringcache and expiringkey also have expire update on containskey --- OpenSim/Framework/ExpiringCacheOS.cs | 49 ++++++++++++++++++++++++++++ OpenSim/Framework/ExpiringKey.cs | 43 ++++++++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/OpenSim/Framework/ExpiringCacheOS.cs b/OpenSim/Framework/ExpiringCacheOS.cs index 7707fda58e..e62caec42a 100644 --- a/OpenSim/Framework/ExpiringCacheOS.cs +++ b/OpenSim/Framework/ExpiringCacheOS.cs @@ -295,6 +295,55 @@ namespace OpenSim.Framework } } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public bool Contains(TKey1 key, int expireMS) + { + return ContainsKey(key, expireMS); + } + + public bool ContainsKey(TKey1 key, int expireMS) + { + bool gotLock = false; + try + { + try { } + finally + { + m_rwLock.EnterUpgradeableReadLock(); + gotLock = true; + } + if(m_expireControl.ContainsKey(key)) + { + bool gotWriteLock = false; + try + { + try { } + finally + { + m_rwLock.EnterWriteLock(); + gotWriteLock = true; + } + expireMS = (expireMS > m_expire) ? expireMS : m_expire; + int now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS; + + m_expireControl[key] = now; + return true; + } + finally + { + if (gotWriteLock) + m_rwLock.ExitWriteLock(); + } + } + return false; + } + finally + { + if (gotLock) + m_rwLock.ExitUpgradeableReadLock(); + } + } + public bool TryGetValue(TKey1 key, out TValue1 value) { bool success; diff --git a/OpenSim/Framework/ExpiringKey.cs b/OpenSim/Framework/ExpiringKey.cs index 0168326cbe..b87bd2b5fc 100644 --- a/OpenSim/Framework/ExpiringKey.cs +++ b/OpenSim/Framework/ExpiringKey.cs @@ -259,6 +259,49 @@ namespace OpenSim.Framework } } + public bool ContainsKey(Tkey1 key, int expireMS) + { + bool gotLock = false; + try + { + try { } + finally + { + m_rwLock.EnterUpgradeableReadLock(); + gotLock = true; + } + if (m_dictionary.ContainsKey(key)) + { + bool gotWriteLock = false; + try + { + try { } + finally + { + m_rwLock.EnterWriteLock(); + gotWriteLock = true; + } + expireMS = (expireMS > m_expire) ? expireMS : m_expire; + int now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS; + + m_dictionary[key] = now; + return true; + } + finally + { + if (gotWriteLock) + m_rwLock.ExitWriteLock(); + } + } + return false; + } + finally + { + if (gotLock) + m_rwLock.EnterUpgradeableReadLock(); + } + } + public bool TryGetValue(Tkey1 key, out int value) { bool success;