public int RunTest()
    {
        int retCode = -10;
        rwls = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
        threadCount = 0;
        oneThreadAccess = 0;

        retCode = DoTesting();

        return retCode;
    }
Ejemplo n.º 2
0
        public static void EnterExit()
        {
            using (ReaderWriterLockSlim rwls = new ReaderWriterLockSlim())
            {
                Assert.False(rwls.IsReadLockHeld);
                rwls.EnterReadLock();
                Assert.True(rwls.IsReadLockHeld);
                rwls.ExitReadLock();
                Assert.False(rwls.IsReadLockHeld);

                Assert.False(rwls.IsUpgradeableReadLockHeld);
                rwls.EnterUpgradeableReadLock();
                Assert.True(rwls.IsUpgradeableReadLockHeld);
                rwls.ExitUpgradeableReadLock();
                Assert.False(rwls.IsUpgradeableReadLockHeld);

                Assert.False(rwls.IsWriteLockHeld);
                rwls.EnterWriteLock();
                Assert.True(rwls.IsWriteLockHeld);
                rwls.ExitWriteLock();
                Assert.False(rwls.IsWriteLockHeld);

                Assert.False(rwls.IsUpgradeableReadLockHeld);
                rwls.EnterUpgradeableReadLock();
                Assert.False(rwls.IsWriteLockHeld);
                Assert.True(rwls.IsUpgradeableReadLockHeld);
                rwls.EnterWriteLock();
                Assert.True(rwls.IsWriteLockHeld);
                rwls.ExitWriteLock();
                Assert.False(rwls.IsWriteLockHeld);
                Assert.True(rwls.IsUpgradeableReadLockHeld);
                rwls.ExitUpgradeableReadLock();
                Assert.False(rwls.IsUpgradeableReadLockHeld);

                Assert.True(rwls.TryEnterReadLock(0));
                rwls.ExitReadLock();

                Assert.True(rwls.TryEnterReadLock(Timeout.InfiniteTimeSpan));
                rwls.ExitReadLock();

                Assert.True(rwls.TryEnterUpgradeableReadLock(0));
                rwls.ExitUpgradeableReadLock();

                Assert.True(rwls.TryEnterUpgradeableReadLock(Timeout.InfiniteTimeSpan));
                rwls.ExitUpgradeableReadLock();

                Assert.True(rwls.TryEnterWriteLock(0));
                rwls.ExitWriteLock();

                Assert.True(rwls.TryEnterWriteLock(Timeout.InfiniteTimeSpan));
                rwls.ExitWriteLock();
            }
        }
Ejemplo n.º 3
0
        public static void ReaderWriterLockSlimPerf()
        {
            ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim();

            foreach (var iteration in Benchmark.Iterations)
            {
                using (iteration.StartMeasurement())
                {
                    rwLock.EnterReadLock();
                    rwLock.ExitReadLock();
                }
            }
        }
Ejemplo n.º 4
0
		public TypeKeyRepository( TypeKeyRepository copiedFrom )
		{
			this._lock = new ReaderWriterLockSlim( LockRecursionPolicy.NoRecursion );

			if ( copiedFrom == null )
			{
				this._table = new Dictionary<RuntimeTypeHandle, object>();
			}
			else
			{
				this._table = copiedFrom.GetClonedTable();
			}
		}
Ejemplo n.º 5
0
        public static void Dispose()
        {
            ReaderWriterLockSlim rwls;

            rwls = new ReaderWriterLockSlim();
            rwls.Dispose();
            Assert.Throws<ObjectDisposedException>(() => rwls.TryEnterReadLock(0));
            Assert.Throws<ObjectDisposedException>(() => rwls.TryEnterUpgradeableReadLock(0));
            Assert.Throws<ObjectDisposedException>(() => rwls.TryEnterWriteLock(0));
            rwls.Dispose();

            for (int i = 0; i < 3; i++)
            {
                rwls = new ReaderWriterLockSlim();
                switch (i)
                {
                    case 0: rwls.EnterReadLock(); break;
                    case 1: rwls.EnterUpgradeableReadLock(); break;
                    case 2: rwls.EnterWriteLock(); break;
                }
                Assert.Throws<SynchronizationLockException>(() => rwls.Dispose());
            }
        }
Ejemplo n.º 6
0
        public static void Ctor()
        {
            ReaderWriterLockSlim rwls;

            using (rwls = new ReaderWriterLockSlim())
            {
                Assert.Equal(LockRecursionPolicy.NoRecursion, rwls.RecursionPolicy);
            }

            using (rwls = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion))
            {
                Assert.Equal(LockRecursionPolicy.NoRecursion, rwls.RecursionPolicy);
            }

            using (rwls = new ReaderWriterLockSlim((LockRecursionPolicy)12345))
            {
                Assert.Equal(LockRecursionPolicy.NoRecursion, rwls.RecursionPolicy);
            }

            using (rwls = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion))
            {
                Assert.Equal(LockRecursionPolicy.SupportsRecursion, rwls.RecursionPolicy);
            }
        }
Ejemplo n.º 7
0
        public static void InvalidTimeouts()
        {
            using (ReaderWriterLockSlim rwls = new ReaderWriterLockSlim())
            {
                Assert.Throws<ArgumentOutOfRangeException>(() => rwls.TryEnterReadLock(-2));
                Assert.Throws<ArgumentOutOfRangeException>(() => rwls.TryEnterUpgradeableReadLock(-3));
                Assert.Throws<ArgumentOutOfRangeException>(() => rwls.TryEnterWriteLock(-4));

                Assert.Throws<ArgumentOutOfRangeException>(() => rwls.TryEnterReadLock(TimeSpan.MaxValue));
                Assert.Throws<ArgumentOutOfRangeException>(() => rwls.TryEnterUpgradeableReadLock(TimeSpan.MinValue));
                Assert.Throws<ArgumentOutOfRangeException>(() => rwls.TryEnterWriteLock(TimeSpan.FromMilliseconds(-2)));
            }
        }
Ejemplo n.º 8
0
    public SubHybridTree(sbyte levelDepth,Vector3 pos)
        : base(levelDepth)
    {
        position = pos+((Vector3.one*size)*0.5f);
        queuedPoints = new List<Vector3>();
        queuedValues = new List<sbyte>();

        rwValueLock = new ReaderWriterLockSlim();
        rwQueueLock = new ReaderWriterLockSlim();
        rwNodePosLock = new ReaderWriterLockSlim();
        rwNodeRightLock = new ReaderWriterLockSlim();
        //position = pos;
    }
Ejemplo n.º 9
0
 internal LockEnumeratorWrapper(ReaderWriterLockSlim locker, IEnumerator <T> enumerator)
     : base(locker, enumerator)
 {
 }
Ejemplo n.º 10
0
 protected DisposableLockBase(ReaderWriterLockSlim rwLock)
 {
     this.rwLock     = rwLock;
     this.isDisposed = false;
 }
Ejemplo n.º 11
0
 /// <summary>
 ///  Initializes a new instance of the <see cref="T:ExitGames.Threading.UpgradeableReadLock"/> struct.
 /// </summary>
 /// <param name="syncObject">The reader writer lock</param>
 private UpgradeableReadLock(ReaderWriterLockSlim syncObject)
 {
     this.syncObject = syncObject;
     this.syncObject.EnterUpgradeableReadLock();
 }
Ejemplo n.º 12
0
 public WriteLockScope(ReaderWriterLockSlim @lock)
 {
     m_lock = @lock;
     m_lock.EnterWriteLock();
 }
Ejemplo n.º 13
0
 public RwLock()
 {
     this.rwLock = new ReaderWriterLockSlim();
 }
        public BinaryFileIntegerArray(string path, int size)
        {
            Lock = new ReaderWriterLockSlim();
            context = new ReadWriteContext(this);
            int fileLength = size * sizeof(int);
            this.path = path;

            if (!File.Exists(path))
            {
                File.WriteAllBytes(path, new byte[fileLength]);
            }
        }
        public PerRequestCacheManager(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;

            _locker = new ReaderWriterLockSlim();
        }
Ejemplo n.º 16
0
 static ParserLog()
 {
     ParserLog._readWriteLock = new ReaderWriterLockSlim();
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReaderWriterSlimLock"/> class.
 /// </summary>
 /// <param name="lock">The reference to <see cref="ReaderWriterLockSlim"/>.</param>
 public ReaderWriterSlimLock(ReaderWriterLockSlim @lock)
 {
     this.@lock = @lock;
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Enters a critical section with <see cref="M:System.Threading.ReaderWriterLockSlim.TryEnterUpgradeableReadLock(System.Int32)"/> and returns a new instance of <see cref="T:ExitGames.Threading.WriteLock"/>.
 /// </summary>
 /// <param name="syncObject">
 /// The reader writer lock.
 /// </param>
 /// <param name="millisecondsTimeout">
 /// The timeout for <see cref="M:System.Threading.ReaderWriterLockSlim.TryEnterUpgradeableReadLock(System.Int32)"/> in milliseconds.
 /// </param>
 /// <returns>A <see cref="T:ExitGames.Threading.UpgradeableReadLock"/> that can be disposed to call <see cref="M:System.Threading.ReaderWriterLockSlim.ExitUpgradeableReadLock"/>.
 /// </returns>
 /// <exception cref="T:ExitGames.Threading.LockTimeoutException">
 /// <see cref="M:System.Threading.ReaderWriterLockSlim.TryEnterUpgradeableReadLock(System.Int32)"/> returned false.
 ///</exception>
 public static IDisposable TryEnter(ReaderWriterLockSlim syncObject, int millisecondsTimeout)
 {
     return(new UpgradeableReadLock(syncObject, millisecondsTimeout));
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Enters a critical section with <see cref="M:System.Threading.ReaderWriterLockSlim.EnterUpgradeableReadLock"/> and returns a new instance of <see cref="T:ExitGames.Threading.UpgradeableReadLock"/>.
 /// </summary>
 /// <param name="syncObject">The reader writer lock.</param>
 /// <returns>
 /// A <see cref="T:ExitGames.Threading.UpgradeableReadLock"/> that can be disposed to call <see cref="M:System.Threading.ReaderWriterLockSlim.ExitUpgradeableReadLock"/>.
 ///</returns>
 public static IDisposable Enter(ReaderWriterLockSlim syncObject)
 {
     return(new UpgradeableReadLock(syncObject));
 }
Ejemplo n.º 20
0
 public static void ReadersMayBeConcurrent()
 {
     using (Barrier barrier = new Barrier(2))
     using (ReaderWriterLockSlim rwls = new ReaderWriterLockSlim())
     {
         Assert.Equal(0, rwls.CurrentReadCount);
         Task.WaitAll(
             Task.Run(() =>
             {
                 rwls.EnterReadLock();
                 barrier.SignalAndWait(); // 1
                 Assert.True(rwls.IsReadLockHeld);
                 barrier.SignalAndWait(); // 2
                 Assert.Equal(2, rwls.CurrentReadCount);
                 barrier.SignalAndWait(); // 3
                 barrier.SignalAndWait(); // 4
                 rwls.ExitReadLock();
             }),
             Task.Run(() =>
             {
                 barrier.SignalAndWait(); // 1
                 rwls.EnterReadLock();
                 barrier.SignalAndWait(); // 2
                 Assert.True(rwls.IsReadLockHeld);
                 Assert.Equal(0, rwls.WaitingReadCount);
                 barrier.SignalAndWait(); // 3
                 rwls.ExitReadLock();
                 barrier.SignalAndWait(); // 4
             }));
         Assert.Equal(0, rwls.CurrentReadCount);
     }
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Creates a new ThreadSafeGenericList object.
 /// </summary>
 public ThreadSafeGenericList()
 {
     _items = new List <T>();
     _lock  = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
 }
Ejemplo n.º 22
0
        static void Main(string[] args)
        {
            Options options;

            try
            {
                options = Options.FromCommandLine(args);
            }
            catch (Options.ParsingException ex)
            {
                LOGGER.Fatal(ex.Message);
                LOGGER.Info(Options.ShowUsage());
                Environment.Exit(-1);
                return;
            }

            server = createDefaultPRServer();
            mutex  = new ReaderWriterLockSlim();
            try
            {
                endPoint = new UdpClient(new IPEndPoint(options.EmulatorIP, options.EmulatorPort));
            }
            catch (Exception ex)
            {
                LOGGER.Fatal("Unable to create UDP listener: " + ex.Message);
                Environment.Exit(-1);
                return;
            }

            for (int i = 0; i < 5; i++)
            {
                Thread thread = new Thread(() => ReporterWorker(options.BattlefieldIP, options.BattlefieldPort))
                {
                    IsBackground = false  // make sure no thread keeps working even if this reached the end
                };
                thread.Start();
            }

            LOGGER.Info("GSEmulator ready at {0}:{1}!", options.EmulatorIP.ToString(), options.EmulatorPort);
            for (string line = Console.ReadLine(); line != null; line = Console.ReadLine())
            {
                try
                {
                    LOGGER.Trace("Parsing: '{0}'", line);
                    Command command = Parser.Parse(line);

                    mutex.EnterWriteLock();
                    command.Execute(ref server);
                }
                catch (Exception ex)
                {
                    LOGGER.Warn(ex.ToString());
                }
                finally { if (mutex.IsWriteLockHeld)
                          {
                              mutex.ExitWriteLock();
                          }
                }
            }


            LOGGER.Warn("Python PIPE was closed");

            // Closing UDP Client
            // Causes worker threads to exit their while loop
            endPoint.Close();

            LOGGER.Info("GSEmulator is shuting down...");
        }
Ejemplo n.º 23
0
 public DisposableWriteLock(ReaderWriterLockSlim rwLock)
     : base(rwLock)
 {
     this.Lock.EnterWriteLock();
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Creates a new ThreadSafeSortedList object.
 /// </summary>
 public ThreadSafeSortedList()
 {
     _items = new SortedList <TK, TV>();
     _lock  = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion);
 }
Ejemplo n.º 25
0
 public UpgradeableReadLockHelper( ReaderWriterLockSlim readerWriterLock ) {
     readerWriterLock.EnterUpgradeableReadLock();
     this.readerWriterLock = readerWriterLock;
 }
Ejemplo n.º 26
0
        // Set methodExecutor, returning an error string if there are any problems (ambiguous match, etc.).
        public void DetermineMethodInfo(CodeActivityMetadata metadata, MruCache <MethodInfo, Func <object, object[], object> > funcCache, ReaderWriterLockSlim locker,
                                        ref MethodExecutor methodExecutor)
        {
            bool returnEarly = false;

            MethodExecutor oldMethodExecutor = methodExecutor;

            methodExecutor = null;
            if (string.IsNullOrEmpty(this.MethodName))
            {
                metadata.AddValidationError(SR.ActivityPropertyMustBeSet("MethodName", this.Parent.DisplayName));
                returnEarly = true;
            }

            Type targetType = this.TargetType;

            // If TargetType and the type of TargetObject are both set, it's an error.
            if (targetType != null && this.TargetObject != null && !this.TargetObject.IsEmpty)
            {
                metadata.AddValidationError(SR.TargetTypeAndTargetObjectAreMutuallyExclusive(this.Parent.GetType().Name, this.Parent.DisplayName));
                returnEarly = true;
            }

            // If TargetType was set, look for a static method. If TargetObject was set, look for an instance method. They can't both be set.
            BindingFlags bindingFlags = this.TargetType != null ? staticBindingFlags : instanceBindingFlags;
            string       bindingType  = bindingFlags == staticBindingFlags ? staticString : instanceString;

            if (targetType == null)
            {
                if (this.TargetObject != null && !this.TargetObject.IsEmpty)
                {
                    targetType = this.TargetObject.ArgumentType;
                }
                else
                {
                    metadata.AddValidationError(SR.OneOfTwoPropertiesMustBeSet("TargetObject", "TargetType", this.Parent.GetType().Name, this.Parent.DisplayName));
                    returnEarly = true;
                }
            }

            // We've had one or more constraint violations already
            if (returnEarly)
            {
                return;
            }

            // Convert OutArgs and InOutArgs to out/ref types before resolution
            Type[] parameterTypes =
                Parameters.Select(argument => argument.Direction == ArgumentDirection.In ? argument.ArgumentType : argument.ArgumentType.MakeByRefType())
                .ToArray();

            Type[] genericTypeArguments = this.GenericTypeArguments.ToArray();

            InheritanceAndParamArrayAwareBinder methodBinder = new InheritanceAndParamArrayAwareBinder(targetType, genericTypeArguments, this.Parent);

            // It may be possible to know (and check) the resultType even if the result won't be assigned anywhere.
            // Used 1.) for detecting async pattern, and 2.) to make sure we selected the correct MethodInfo.
            Type resultType = this.ResultType;

            if (this.RunAsynchronously)
            {
                int    formalParamCount          = parameterTypes.Length;
                Type[] beginMethodParameterTypes = new Type[formalParamCount + 2];
                for (int i = 0; i < formalParamCount; i++)
                {
                    beginMethodParameterTypes[i] = parameterTypes[i];
                }
                beginMethodParameterTypes[formalParamCount]     = typeof(AsyncCallback);
                beginMethodParameterTypes[formalParamCount + 1] = typeof(object);

                Type[] endMethodParameterTypes = { typeof(IAsyncResult) };

                this.beginMethod = Resolve(targetType, "Begin" + this.MethodName, bindingFlags,
                                           methodBinder, beginMethodParameterTypes, genericTypeArguments, true);
                if (this.beginMethod != null && !this.beginMethod.ReturnType.Equals(typeof(IAsyncResult)))
                {
                    this.beginMethod = null;
                }
                this.endMethod = Resolve(targetType, "End" + this.MethodName, bindingFlags,
                                         methodBinder, endMethodParameterTypes, genericTypeArguments, true);
                if (this.endMethod != null && resultType != null && !TypeHelper.AreTypesCompatible(this.endMethod.ReturnType, resultType))
                {
                    metadata.AddValidationError(SR.ReturnTypeIncompatible(this.endMethod.ReturnType.Name, MethodName, targetType.Name, this.Parent.DisplayName, resultType.Name));
                    this.endMethod = null;
                    return;
                }

                if (this.beginMethod != null && this.endMethod != null && this.beginMethod.IsStatic == this.endMethod.IsStatic)
                {
                    if (!(oldMethodExecutor is AsyncPatternMethodExecutor) ||
                        !((AsyncPatternMethodExecutor)oldMethodExecutor).IsTheSame(this.beginMethod, this.endMethod))
                    {
                        methodExecutor = new AsyncPatternMethodExecutor(metadata, this.beginMethod, this.endMethod, this.Parent,
                                                                        this.TargetType, this.TargetObject, this.Parameters, this.Result, funcCache, locker);
                    }
                    else
                    {
                        methodExecutor = new AsyncPatternMethodExecutor((AsyncPatternMethodExecutor)oldMethodExecutor,
                                                                        this.TargetType, this.TargetObject, this.Parameters, this.Result);
                    }
                    return;
                }
            }

            MethodInfo result;

            try
            {
                result = Resolve(targetType, this.MethodName, bindingFlags,
                                 methodBinder, parameterTypes, genericTypeArguments, false);
            }
            catch (AmbiguousMatchException)
            {
                metadata.AddValidationError(SR.DuplicateMethodFound(targetType.Name, bindingType, MethodName, this.Parent.DisplayName));
                return;
            }

            if (result == null)
            {
                metadata.AddValidationError(SR.PublicMethodWithMatchingParameterDoesNotExist(targetType.Name, bindingType, MethodName, this.Parent.DisplayName));
                return;
            }
            else if (resultType != null && !TypeHelper.AreTypesCompatible(result.ReturnType, resultType))
            {
                metadata.AddValidationError(
                    SR.ReturnTypeIncompatible(result.ReturnType.Name, MethodName,
                                              targetType.Name, this.Parent.DisplayName, resultType.Name));
                return;
            }
            else
            {
                this.syncMethod = result;
                if (this.RunAsynchronously)
                {
                    if (!(oldMethodExecutor is AsyncWaitCallbackMethodExecutor) ||
                        !((AsyncWaitCallbackMethodExecutor)oldMethodExecutor).IsTheSame(this.syncMethod))
                    {
                        methodExecutor = new AsyncWaitCallbackMethodExecutor(metadata, this.syncMethod, this.Parent,
                                                                             this.TargetType, this.TargetObject, this.Parameters, this.Result, funcCache, locker);
                    }
                    else
                    {
                        methodExecutor = new AsyncWaitCallbackMethodExecutor((AsyncWaitCallbackMethodExecutor)oldMethodExecutor,
                                                                             this.TargetType, this.TargetObject, this.Parameters, this.Result);
                    }
                }
                else if (!(oldMethodExecutor is SyncMethodExecutor) ||
                         !((SyncMethodExecutor)oldMethodExecutor).IsTheSame(this.syncMethod))
                {
                    methodExecutor = new SyncMethodExecutor(metadata, this.syncMethod, this.Parent, this.TargetType,
                                                            this.TargetObject, this.Parameters, this.Result, funcCache, locker);
                }
                else
                {
                    methodExecutor = new SyncMethodExecutor((SyncMethodExecutor)oldMethodExecutor, this.TargetType,
                                                            this.TargetObject, this.Parameters, this.Result);
                }
            }
        }
Ejemplo n.º 27
0
 public WriteLockHelper( ReaderWriterLockSlim readerWriterLock ) {
     readerWriterLock.EnterWriteLock();
     this.readerWriterLock = readerWriterLock;
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WriteLockDisposable"/> class.
 /// </summary>
 /// <param name="rwLock">The rw lock.</param>
 public WriteLockDisposable(ReaderWriterLockSlim rwLock)
 {
     _rwLock = rwLock;
     _rwLock.EnterWriteLock();
 }
Ejemplo n.º 29
0
 public ObservableCollectionSafe()
 {
     _coll = new Collection <T>();
     _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
 }
Ejemplo n.º 30
0
 public EvenCartLocker(ReaderWriterLockSlim @lock)
 {
     _lock = @lock;
     _lock.EnterWriteLock();
 }
Ejemplo n.º 31
0
 public InMemoryEnvironmentStateRepository()
 {
     _lock             = new ReaderWriterLockSlim();
     _environmentState = new EnvironmentState(-1, new List <ToggleState>());
 }
Ejemplo n.º 32
0
    public static void QueueTask(int LinePriority,Task task,Task post)
    {
        if (taskPoolObject == null)
        {
            taskPoolObject = new GameObject("_taskPoolObject");
            taskPoolObject.AddComponent<TaskPool>();

            JobQueue = new List<Job>();
            postJobQueue = new List<Job>();
            rwLock = new ReaderWriterLockSlim();

            tasks = new List<Task>();

            if (workers == null)
            {
                workers = new ThreadWorker[8];
                for (int i = 0; i < 8; i++)
                {
                    workers[i] = new ThreadWorker(i);
                    workers[i].workerThread = new Thread(new ThreadStart(workers[i].Work));
                    workers[i].workerThread.Start();

                }
                //Debug.Log("started "+workers.Count.ToString()+" Workers");
            }
        }
        Job InsertJob = new Job(task,post,LinePriority);
        rwLock.EnterUpgradeableReadLock();
        try
        {
            if (JobQueue == null)
            {
                rwLock.EnterWriteLock();
                try
                {
                    JobQueue = new List<Job>();

                }
                finally
                {
                    rwLock.ExitWriteLock();

                }
            }
            if (JobQueue != null)
            {

                rwLock.EnterWriteLock();
                try
                {
                    JobQueue.Add(InsertJob);
                }
                finally
                {
                    rwLock.ExitWriteLock();

                }
            }
        }
        finally
        {
            rwLock.ExitUpgradeableReadLock();
        }
    }
Ejemplo n.º 33
0
 public void Dispose()
 {
     _lock?.Dispose();
     _lock = null;
 }
Ejemplo n.º 34
0
 public SubPathfinder(WorldTree target)
 {
     rwLock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion);
     pathQueue = new List<AIPath>();
     outsideQueue = new List<AIPath>();
     syncedTree = new WorldTree(target.GetMaxLevelDepth());
     targetTree = target;
 }
 public UpgradeableReadLockDisposable(ReaderWriterLockSlim rwLock)
 {
     this._rwLock = rwLock;
 }
Ejemplo n.º 36
0
        public static void DeadlockAvoidance()
        {
            using (ReaderWriterLockSlim rwls = new ReaderWriterLockSlim())
            {
                rwls.EnterReadLock();
                Assert.Throws<LockRecursionException>(() => rwls.EnterReadLock());
                Assert.Throws<LockRecursionException>(() => rwls.EnterUpgradeableReadLock());
                Assert.Throws<LockRecursionException>(() => rwls.EnterWriteLock());
                rwls.ExitReadLock();

                rwls.EnterUpgradeableReadLock();
                rwls.EnterReadLock();
                Assert.Throws<LockRecursionException>(() => rwls.EnterReadLock());
                rwls.ExitReadLock();
                Assert.Throws<LockRecursionException>(() => rwls.EnterUpgradeableReadLock());
                rwls.EnterWriteLock();
                Assert.Throws<LockRecursionException>(() => rwls.EnterWriteLock());
                rwls.ExitWriteLock();
                rwls.ExitUpgradeableReadLock();

                rwls.EnterWriteLock();
                Assert.Throws<LockRecursionException>(() => rwls.EnterReadLock());
                Assert.Throws<LockRecursionException>(() => rwls.EnterUpgradeableReadLock());
                Assert.Throws<LockRecursionException>(() => rwls.EnterWriteLock());
                rwls.ExitWriteLock();
            }

            using (ReaderWriterLockSlim rwls = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion))
            {
                rwls.EnterReadLock();
                Assert.Throws<LockRecursionException>(() => rwls.EnterWriteLock());
                rwls.EnterReadLock();
                Assert.Throws<LockRecursionException>(() => rwls.EnterUpgradeableReadLock());
                rwls.ExitReadLock();
                rwls.ExitReadLock();

                rwls.EnterUpgradeableReadLock();
                rwls.EnterReadLock();
                rwls.EnterUpgradeableReadLock();
                rwls.ExitUpgradeableReadLock();
                rwls.EnterReadLock();
                rwls.ExitReadLock();
                rwls.ExitReadLock();
                rwls.EnterWriteLock();
                rwls.EnterWriteLock();
                rwls.ExitWriteLock();
                rwls.ExitWriteLock();
                rwls.ExitUpgradeableReadLock();

                rwls.EnterWriteLock();
                rwls.EnterReadLock();
                rwls.ExitReadLock();
                rwls.EnterUpgradeableReadLock();
                rwls.ExitUpgradeableReadLock();
                rwls.EnterWriteLock();
                rwls.ExitWriteLock();
                rwls.ExitWriteLock();
            }
        }
Ejemplo n.º 37
0
 private WriteLock(ReaderWriterLockSlim lockSlim)
 {
     _LockSlim = lockSlim;
     _LockSlim.EnterWriteLock();
 }
Ejemplo n.º 38
0
        public static void InvalidExits(LockRecursionPolicy policy)
        {
            using (ReaderWriterLockSlim rwls = new ReaderWriterLockSlim(policy))
            {
                Assert.Throws<SynchronizationLockException>(() => rwls.ExitReadLock());
                Assert.Throws<SynchronizationLockException>(() => rwls.ExitUpgradeableReadLock());
                Assert.Throws<SynchronizationLockException>(() => rwls.ExitWriteLock());

                rwls.EnterReadLock();
                Assert.Throws<SynchronizationLockException>(() => rwls.ExitUpgradeableReadLock());
                Assert.Throws<SynchronizationLockException>(() => rwls.ExitWriteLock());
                rwls.ExitReadLock();

                rwls.EnterUpgradeableReadLock();
                Assert.Throws<SynchronizationLockException>(() => rwls.ExitReadLock());
                Assert.Throws<SynchronizationLockException>(() => rwls.ExitWriteLock());
                rwls.ExitUpgradeableReadLock();

                rwls.EnterWriteLock();
                Assert.Throws<SynchronizationLockException>(() => rwls.ExitReadLock());
                Assert.Throws<SynchronizationLockException>(() => rwls.ExitUpgradeableReadLock());
                rwls.ExitWriteLock();

                using (Barrier barrier = new Barrier(2))
                {
                    Task t = Task.Factory.StartNew(() =>
                    {
                        rwls.EnterWriteLock();
                        barrier.SignalAndWait();
                        barrier.SignalAndWait();
                        rwls.ExitWriteLock();
                    }, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);

                    barrier.SignalAndWait();
                    Assert.Throws<SynchronizationLockException>(() => rwls.ExitWriteLock());
                    barrier.SignalAndWait();

                    t.GetAwaiter().GetResult();
                }
            }
        }
Ejemplo n.º 39
0
 private ReadLock(ReaderWriterLockSlim lockSlim)
 {
     _LockSlim = lockSlim;
     _LockSlim.TryEnterReadLock(TimeSpan.FromSeconds(ReadTimeout));
 }
Ejemplo n.º 40
0
 public static void WritersAreMutuallyExclusiveFromWriters()
 {
     using (Barrier barrier = new Barrier(2))
     using (ReaderWriterLockSlim rwls = new ReaderWriterLockSlim())
     {
         Task.WaitAll(
             Task.Run(() =>
             {
                 rwls.EnterWriteLock();
                 barrier.SignalAndWait();
                 Assert.True(rwls.IsWriteLockHeld);
                 barrier.SignalAndWait();
                 rwls.ExitWriteLock();
             }),
             Task.Run(() =>
             {
                 barrier.SignalAndWait();
                 Assert.False(rwls.TryEnterWriteLock(0));
                 Assert.False(rwls.IsReadLockHeld);
                 barrier.SignalAndWait();
             }));
     }
 }
Ejemplo n.º 41
0
 public WriterLockZone(ReaderWriterLockSlim rwl)
     : this(new WriterLockWrapper(rwl))
 { }
Ejemplo n.º 42
0
 public static void WriterToUpgradeableReaderChain()
 {
     using (AutoResetEvent are = new AutoResetEvent(false))
     using (ReaderWriterLockSlim rwls = new ReaderWriterLockSlim())
     {
         rwls.EnterWriteLock();
         Task t = Task.Factory.StartNew(() =>
         {
             Assert.False(rwls.TryEnterUpgradeableReadLock(TimeSpan.FromMilliseconds(10)));
             Task.Run(() => are.Set()); // ideally this won't fire until we've called EnterReadLock, but it's a benign race in that the test will succeed either way
             rwls.EnterUpgradeableReadLock();
             rwls.ExitUpgradeableReadLock();
         }, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
         are.WaitOne();
         rwls.ExitWriteLock();
         t.GetAwaiter().GetResult();
     }
 }
Ejemplo n.º 43
0
 public void Clone(Connection connection)
 {
     this.SqlDatabase = connection.SqlDatabase;
     this.SqlServerType = connection.SqlServerType;
     this.m_connection = connection.m_connection;
     this.m_bGlobal = connection.m_bGlobal;
     this.m_lock = connection.m_lock;
     this.m_nLockTimeout = connection.m_nLockTimeout;
     this.m_nOpenCount = connection.m_nOpenCount;
 }
Ejemplo n.º 44
0
 private UpdateLock(ReaderWriterLockSlim lockSlim)
 {
     _LockSlim = lockSlim;
     _LockSlim.EnterUpgradeableReadLock();
 }
 public WriteLock(ReaderWriterLockSlim locks)
     : base(locks)
 {
     Locks.GetWriteLock(_Locks);
 }
Ejemplo n.º 46
0
 public WriterLockWrapper(ReaderWriterLockSlim rwl)
     : base(rwl)
 { }
Ejemplo n.º 47
0
 public ConcurrentEnumerator(IEnumerable <T> inner, ReaderWriterLockSlim @lock)
 {
     this._lock = @lock;
     this._lock.EnterReadLock();
     this._inner = inner.GetEnumerator();
 }
Ejemplo n.º 48
0
 public ConcurrentList(int capacity)
 {
     this._lock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion);
     this._list = new List <T>(capacity);
 }
Ejemplo n.º 49
0
 public ConcurrentList(IEnumerable <T> items)
 {
     this._lock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion);
     this._list = new List <T>(items);
 }
Ejemplo n.º 50
0
		public TypeKeyRepository( Dictionary<RuntimeTypeHandle, object> table )
		{
			this._lock = new ReaderWriterLockSlim( LockRecursionPolicy.NoRecursion );
			this._table = table;
		}
Ejemplo n.º 51
0
 protected AbstractReaderWriterLockWrapper(ReaderWriterLockSlim rwl)
 {
     BaseLock = rwl;
 }