public ExpiringKey(int expireCheckTimeinMS) { m_dictionary = new Dictionary <Tkey1, int>(); m_rwLock = new ReaderWriterLockSlim(); m_startTS = Util.GetTimeStampMS(); m_expire = (expireCheckTimeinMS > MINEXPIRECHECK) ? m_expire = expireCheckTimeinMS : MINEXPIRECHECK; }
public void Add(Tkey1 key) { bool gotLock = false; int now = (int)(Util.GetTimeStampMS() - m_startTS) + m_expire; try { try { } finally { m_rwLock.EnterWriteLock(); gotLock = true; } m_dictionary[key] = now; CheckTimer(); } finally { if (gotLock) { m_rwLock.ExitWriteLock(); } } }
public ExpiringKey() { m_dictionary = new Dictionary <Tkey1, int>(); m_rwLock = new ReaderWriterLockSlim(); m_expire = MINEXPIRECHECK; m_startTS = Util.GetTimeStampMS(); }
public void Add(Tkey1 key, int expireMS) { bool gotLock = false; int now; if (expireMS > 0) { expireMS = (expireMS > m_expire) ? expireMS : m_expire; now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS; } else { now = int.MinValue; } try { try { } finally { m_rwLock.EnterWriteLock(); gotLock = true; } m_dictionary[key] = now; CheckTimer(); } finally { if (gotLock) { m_rwLock.ExitWriteLock(); } } }
public void Add(TKey1 key, TValue1 val, int expireMS) { bool gotLock = false; expireMS = (expireMS > m_expire) ? expireMS : m_expire; int now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS; try { try { } finally { m_rwLock.EnterWriteLock(); gotLock = true; } m_expireControl[key] = now; m_values[key] = val; CheckTimer(); } finally { if (gotLock) { m_rwLock.ExitWriteLock(); } } }
public ExpiringCacheOS(int expireCheckTimeinMS) { m_expireControl = new Dictionary <TKey1, int>(); m_values = new Dictionary <TKey1, TValue1>(); m_rwLock = new ReaderWriterLockSlim(); m_startTS = Util.GetTimeStampMS(); m_expire = (expireCheckTimeinMS > MINEXPIRECHECK) ? m_expire = expireCheckTimeinMS : MINEXPIRECHECK; }
public LandData() { _globalID = UUID.Random(); SeeAVs = true; AnyAVSounds = true; GroupAVSounds = true; LastDwellTimeMS = Util.GetTimeStampMS(); }
public bool TryGetValue(TKey1 key, int expireMS, out TValue1 value) { bool success; bool gotLock = false; try { try { } finally { m_rwLock.EnterUpgradeableReadLock(); gotLock = true; } success = m_values.TryGetValue(key, out value); if (success) { bool gotWriteLock = false; try { try { } finally { m_rwLock.EnterWriteLock(); gotWriteLock = true; } int now; if (expireMS > 0) { expireMS = (expireMS > m_expire) ? expireMS : m_expire; now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS; } else { now = int.MinValue; } m_expireControl[key] = now; } finally { if (gotWriteLock) { m_rwLock.ExitWriteLock(); } } } } finally { if (gotLock) { m_rwLock.ExitUpgradeableReadLock(); } } return(success); }
public LandData() { _globalID = UUID.Random(); SeeAVs = true; AnyAVSounds = true; GroupAVSounds = true; LastDwellTimeMS = Util.GetTimeStampMS(); EnvironmentVersion = -1; Environment = null; }
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; } int now; if (expireMS > 0) { expireMS = (expireMS > m_expire) ? expireMS : m_expire; now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS; } else { now = int.MinValue; } m_dictionary[key] = now; return(true); } finally { if (gotWriteLock) { m_rwLock.ExitWriteLock(); } } } return(false); } finally { if (gotLock) { m_rwLock.EnterUpgradeableReadLock(); } } }
private void Purge(object ignored) { bool gotLock = false; int now = (int)(Util.GetTimeStampMS() - m_startTS); try { try { } finally { m_rwLock.EnterWriteLock(); gotLock = true; } if (m_expireControl.Count == 0) { DisposeTimer(); return; } List <TKey1> expired = new List <TKey1>(m_expireControl.Count); foreach (KeyValuePair <TKey1, int> kvp in m_expireControl) { if (kvp.Value < now) { expired.Add(kvp.Key); } } foreach (TKey1 key in expired) { m_expireControl.Remove(key); m_values.Remove(key); } if (m_expireControl.Count == 0) { DisposeTimer(); } else { m_purgeTimer.Change(m_expire, Timeout.Infinite); } } finally { if (gotLock) { m_rwLock.ExitWriteLock(); } } }
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(); } } }
private void Purge(object ignored) { bool gotLock = false; try { try { } finally { m_rwLock.EnterUpgradeableReadLock(); gotLock = true; } if (m_dictionary.Count == 0) { DisposeTimer(); return; } int now = (int)(Util.GetTimeStampMS() - m_startTS); List <Tkey1> expired = new List <Tkey1>(m_dictionary.Count); foreach (KeyValuePair <Tkey1, int> kvp in m_dictionary) { int expire = kvp.Value; if (expire > 0 && expire < now) { expired.Add(kvp.Key); } } if (expired.Count > 0) { bool gotWriteLock = false; try { try { } finally { m_rwLock.EnterWriteLock(); gotWriteLock = true; } foreach (Tkey1 key in expired) { m_dictionary.Remove(key); } } finally { if (gotWriteLock) { m_rwLock.ExitWriteLock(); } } if (m_dictionary.Count == 0) { DisposeTimer(); } else { m_purgeTimer.Change(m_expire, Timeout.Infinite); } } else { m_purgeTimer.Change(m_expire, Timeout.Infinite); } } finally { if (gotLock) { m_rwLock.ExitUpgradeableReadLock(); } } }