예제 #1
0
        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();
                }
            }
        }
예제 #2
0
 public void Add(TKey key, TValue value)
 {
     LockQ.EnterWriteLock();
     try
     {
         dict.Add(key, value);
     }
     finally
     {
         LockQ.ExitWriteLock();
     }
 }
예제 #3
0
 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();
     }
 }
예제 #5
0
 public virtual bool Remove(KeyValuePair <TKey, TValue> item)
 {
     LockQ.EnterWriteLock();
     try
     {
         return(dict.Remove(item));
     }
     finally
     {
         LockQ.ExitWriteLock();
     }
 }
예제 #6
0
 public virtual void Add(KeyValuePair <TKey, TValue> item)
 {
     LockQ.EnterWriteLock();
     try
     {
         dict.Add(item);
     }
     finally
     {
         LockQ.ExitWriteLock();
     }
 }
예제 #7
0
 // 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();
     }
 }