public TValue this[TKey key] { get { LockQ.EnterReadLock(); try { return(dict[key]); } finally { LockQ.ExitReadLock(); } } set { LockQ.EnterWriteLock(); try { dict[key] = value; } finally { LockQ.ExitWriteLock(); } } }
public void Add(TKey key, TValue value) { LockQ.EnterWriteLock(); try { dict.Add(key, value); } finally { LockQ.ExitWriteLock(); } }
public void Clear() { LockQ.EnterWriteLock(); try { dict.Clear(); } finally { LockQ.ExitWriteLock(); } }
public bool Remove(TKey key) { LockQ.EnterWriteLock(); try { return(dict.Remove(key)); } finally { LockQ.ExitWriteLock(); } }
public virtual bool Remove(KeyValuePair <TKey, TValue> item) { LockQ.EnterWriteLock(); try { return(dict.Remove(item)); } finally { LockQ.ExitWriteLock(); } }
public virtual void Add(KeyValuePair <TKey, TValue> item) { LockQ.EnterWriteLock(); try { dict.Add(item); } finally { LockQ.ExitWriteLock(); } }
// This is the internal dictionary that we are wrapping public void Update(TKey key, ref TValue value) { LockQ.EnterWriteLock(); try { dict[key] = value; } finally { LockQ.ExitWriteLock(); } }
/// <summary> /// Merge does a blind remove, and then add. Basically a blind Upsert. /// </summary> /// <param name = "key">Key to lookup</param> /// <param name = "newValue">New Value</param> public void MergeSafe(TKey key, TValue newValue) { LockQ.EnterWriteLock(); try { // take a writelock immediately since we will always be writing if (dict.ContainsKey(key)) { dict.Remove(key); } dict.Add(key, newValue); } finally { LockQ.ExitWriteLock(); } }
/// <summary> /// This is a blind remove. Prevents the need to check for existence first. /// </summary> /// <param name = "key">Key to remove</param> public void RemoveSafe(TKey key) { LockQ.EnterReadLock(); try { if (dict.ContainsKey(key)) { LockQ.EnterWriteLock(); } try { dict.Remove(key); } finally { LockQ.ExitWriteLock(); } } finally { LockQ.ExitReadLock(); } }