Example #1
0
 internal void Free(StringLockInfo item)
 {
     p_Locks.Remove(item);
     item.IsDisposed = true;
     item.Owner      = null;
     //if (!p_Locks.Remove(item))
     //    throw new Exception(LocalResource.StringLockInfoCollection_Error_1);
     //item.IsDisposed = true;
     //item.Owner = null;
     //p_Frees.Add(item);
 }
Example #2
0
 private static bool ReadIsLock(StringLockInfo value, string key)
 {
     //key已锁定,如果不是读锁则已锁定
     if (string.Equals(value.Key, key, StringComparison.OrdinalIgnoreCase))
     {
         return(!value.IsRead);
     }
     //已有key的子键锁定,如果不是读锁则已锁定
     if (value.Key.IndexOf(key + ".") == 0)
     {
         return(!value.IsRead);
     }
     //key是锁定键的子键,如果不是读锁则已锁定
     if (key.IndexOf(value.Key + ".") == 0)
     {
         return(!value.IsRead);
     }
     return(false);
 }
Example #3
0
 private static bool WriteIsLocked(StringLockInfo value, string key)
 {
     //key已锁定,已锁定
     if (string.Equals(value.Key, key, StringComparison.OrdinalIgnoreCase))
     {
         return(true);
     }
     //已有key的子键锁定,已锁定
     if (value.Key.IndexOf(key + ".") == 0)
     {
         return(true);
     }
     //key是锁定键的子键,已锁定
     if (key.IndexOf(value.Key + ".") == 0)
     {
         return(true);
     }
     return(false);
 }
Example #4
0
 private bool TryGet(IEnumerable <string> readlocks, IEnumerable <string> writelocks, IList <StringLockInfo> locks)
 {
     if (readlocks != null)
     {
         foreach (var k in readlocks)
         {
             if (!StringLockHelper.TryLockRead(p_Locks, k))
             {
                 return(false);
             }
         }
     }
     if (writelocks != null)
     {
         foreach (var k in writelocks)
         {
             if (!StringLockHelper.TryLockWrite(p_Locks, k))
             {
                 return(false);
             }
         }
     }
     if (readlocks != null)
     {
         foreach (var k in readlocks)
         {
             StringLockInfo a = GetFromFree(k, true);
             p_Locks.Add(a);
             locks.Add(a);
         }
     }
     if (writelocks != null)
     {
         foreach (var k in writelocks)
         {
             StringLockInfo a = GetFromFree(k, false);
             p_Locks.Add(a);
             locks.Add(a);
         }
     }
     return(true);
 }