Esempio n. 1
0
 public static int get_WaitingWriteCount(Original::ReaderWriterLockSlim @lock)
 {
     return(WrapProperty <int>(
                @lock,
                delegate() { return @lock.WaitingWriteCount; },
                MSyncVarOp.RWVAR_READ,
                "ReaderWriterLockSlim.WaitingWriteCount"));
 }
Esempio n. 2
0
 public static bool get_IsWriteLockHeld(Original::ReaderWriterLockSlim @lock)
 {
     return(WrapProperty <bool>(
                @lock,
                delegate() { return @lock.IsWriteLockHeld; },
                MSyncVarOp.RWVAR_READ,
                "ReaderWriterLockSlim.IsWriteLockHeld"));
 }
Esempio n. 3
0
 public static void EnterUpgradeableReadLock(Original::ReaderWriterLockSlim @lock)
 {
     Helper.WrapAcquire(
         delegate() { @lock.EnterUpgradeableReadLock(); return(false); },
         delegate() { return(@lock.TryEnterUpgradeableReadLock(0)); },
         @lock,
         MSyncVarOp.LOCK_ACQUIRE,
         "ReaderWriterLockSlim.EnterUpgradeableReadLock"
         );
 }
Esempio n. 4
0
 public static T WrapProperty <T>(Original::ReaderWriterLockSlim @lock, PropertyDel <T> property, MSyncVarOp mop, string instrMethod)
 {
     return(Helper.SimpleWrap <T>(
                delegate(ClrSyncManager manager)
     {
         manager.SetMethodInfo(instrMethod);
         manager.SyncVarAccess(@lock, mop);
         T ret;
         try {
             ret = property();
         } catch (Exception e) {
             manager.CommitSyncVarAccess();
             throw e;
         };
         manager.CommitSyncVarAccess();
         return ret;
     },
                delegate()
     {
         return property();
     }));
 }
Esempio n. 5
0
        public static bool TryEnterRaw(Original::ReaderWriterLockSlim @lock, int millisecondsTimeout, string name, MODE mode)
        {
            if (@lock == null)
            {
                throw new ArgumentNullException();
            }
            if (millisecondsTimeout < 0 && millisecondsTimeout != Timeout.Infinite)
            {
                throw new ArgumentOutOfRangeException();
            }

            return(Helper.SimpleWrap <bool>(
                       delegate(ClrSyncManager manager)
            {
                bool b;
                while (true)
                {
                    try
                    {
                        manager.SetMethodInfo(name);
                        manager.SyncVarAccess(@lock, MSyncVarOp.LOCK_ACQUIRE);
                        if (mode == MODE.READ)
                        {
                            b = @lock.TryEnterReadLock(0);
                        }
                        else if (mode == MODE.UPGRADEABLE_READ)
                        {
                            b = @lock.TryEnterUpgradeableReadLock(0);
                        }
                        else
                        {
                            b = @lock.TryEnterWriteLock(0);
                        }
                        if (!b && millisecondsTimeout == Timeout.Infinite)
                        {
                            manager.LocalBacktrack();
                            continue;
                        }
                    }
                    catch (Exception e)
                    {
                        manager.CommitSyncVarAccess();
                        throw e;
                    }
                    if (!b)
                    {
                        manager.MarkTimeout();
                    }
                    manager.CommitSyncVarAccess();
                    break;
                }
                return b;
            },
                       delegate()
            {
                bool b;
                if (mode == MODE.READ)
                {
                    b = @lock.TryEnterReadLock(millisecondsTimeout);
                }
                else if (mode == MODE.UPGRADEABLE_READ)
                {
                    b = @lock.TryEnterUpgradeableReadLock(millisecondsTimeout);
                }
                else
                {
                    b = @lock.TryEnterWriteLock(millisecondsTimeout);
                }
                return b;
            }));
        }
Esempio n. 6
0
 public static bool TryEnterUpgradeableReadLock(Original::ReaderWriterLockSlim @lock, TimeSpan ts)
 {
     return(TryEnterRaw(@lock, (int)ts.TotalMilliseconds, "TryEnterUpgradeableReadLock", MODE.UPGRADEABLE_READ));
 }
Esempio n. 7
0
 public static bool TryEnterUpgradeableReadLock(Original::ReaderWriterLockSlim @lock, int millisecondsTimeout)
 {
     return(TryEnterRaw(@lock, millisecondsTimeout, "TryEnterUpgradeableReadLock", MODE.UPGRADEABLE_READ));
 }
Esempio n. 8
0
 public static bool TryEnterWriteLock(Original::ReaderWriterLockSlim @lock, TimeSpan timeSpan)
 {
     return(TryEnterRaw(@lock, (int)timeSpan.TotalMilliseconds, "TryEnterWriteLock", MODE.WRITE));
 }
Esempio n. 9
0
 public static bool TryEnterWriteLock(Original::ReaderWriterLockSlim @lock, int millisecondsTimeout)
 {
     return(TryEnterRaw(@lock, millisecondsTimeout, "TryEnterWriteLock", MODE.WRITE));
 }
Esempio n. 10
0
 public static void ExitWriteLock(Original::ReaderWriterLockSlim @lock)
 {
     Helper.WrapRelease(@lock, MSyncVarOp.LOCK_RELEASE,
                        delegate(object o) { @lock.ExitWriteLock(); return(false); },
                        "ReaderWriterLockSlim.ExitWriteLock");
 }