System.Threading.ReaderWriterLockSlim.EnterReadLock()

Here are the examples of the csharp api System.Threading.ReaderWriterLockSlim.EnterReadLock() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

773 Examples 7

19 View Source File : NetworkManager.cs
License : GNU Affero General Public License v3.0
Project Creator : Rawaho

public static Session FindSessionByCharacter(CharacterObject character)
        {
            mutex.EnterReadLock();
            try
            {
                return sessions.SingleOrDefault(s => s.State == SessionState.SignedIn && s.Character == character);
            }
            finally
            {
                mutex.ExitReadLock();
            }
        }

19 View Source File : NetworkManager.cs
License : GNU Affero General Public License v3.0
Project Creator : Rawaho

public static void Update(double lastTick)
        {
            // remove any sessions needing to be cleaned up
            while (pendingRemove.Count > 0)
            {
                mutex.EnterWriteLock();
                try
                {
                    sessions.Remove(pendingRemove.Dequeue());
                }
                finally
                {
                    mutex.ExitWriteLock();
                }
            }

            // store any pending sessions and start receiving data
            while (!pendingAdd.IsEmpty)
            {
                mutex.EnterWriteLock();
                try
                {
                    if (pendingAdd.TryDequeue(out Session session))
                    {
                        sessions.Add(session);
                        session.BeginReceive();
                    }
                }
                finally
                {
                    mutex.ExitWriteLock();
                }
            }

            mutex.EnterReadLock();
            try
            {
                foreach (Session session in sessions)
                    session.Update(lastTick);
            }
            finally
            {
                mutex.ExitReadLock();
            }
        }

19 View Source File : LruCacheStorage.cs
License : MIT License
Project Creator : reaqtive

public IReference<T> GetEntry(T value)
        {
            CheckDisposed();

            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var entry = default(Entry);

            _lock.EnterReadLock();

            try
            {
                while (true)
                {
                    if (!_cache.TryGetValue(value, out entry))
                    {
                        entry = new Entry(value);
                        if (_cache.TryAdd(value, entry) && entry.TryIncrement())
                        {
                            break;
                        }
                    }
                    else if (entry.TryIncrement())
                    {
                        break;
                    }
                }
            }
            finally
            {
                _lock.ExitReadLock();
            }

            Prune();

            return entry;
        }

19 View Source File : LruCacheStorage.cs
License : MIT License
Project Creator : reaqtive

public void ReleaseEntry(IReference<T> entry)
        {
            CheckDisposed();

            if (entry == null)
            {
                throw new ArgumentNullException(nameof(entry));
            }
            if (entry.Value == null)
            {
                throw new ArgumentException("Value contained in the entry cannot be null.", nameof(entry));
            }

            var cached = default(Entry);

            _lock.EnterReadLock();

            try
            {
                if (_cache.TryGetValue(entry.Value, out cached) && ReferenceEquals(entry, cached))
                {
                    try
                    {
                        // Purposefully empty; we need to make sure there is no interruption
                        // between decrementing the reference count and removing the entry.
                    }
                    finally
                    {
                        if (cached.Decrement() == 0)
                        {
#if DEBUG
                            var removed = _cache.TryRemove(entry.Value, out cached);
                            Debug.replacedert(removed);
#else
                            _cache.TryRemove(entry.Value, out cached);
#endif
                        }
                    }
                }
            }
            finally
            {
                _lock.ExitReadLock();
            }
        }

19 View Source File : ReactiveEntityCollection.cs
License : MIT License
Project Creator : reaqtive

public bool TryRemove(TKey key, out TValue value)
        {
            // Lock required, to prevent the case of an entry appearing in both
            // the cloned collection of entries and the list of removed keys.
            // If the cloning occurs while an entry is being removed, there is
            // some chance that the entries will be cloned before the entry is
            // removed, and then the removed keys will be cloned after the
            // entry key is added to the list of removed keys.
            _lock.EnterReadLock();

            try
            {
                if (_collection.TryRemove(key, out value))
                {
                    _removedKeys.TryAdd(key, value: default);
                    return true;
                }

                return false;
            }
            finally
            {
                _lock.ExitReadLock();
            }
        }

19 View Source File : AES.cs
License : MIT License
Project Creator : ren8179

public static string EncryptFile(string inputFile, string outputFile, string preplacedword)
        {
            ReaderWriterLockSlim locker = new ReaderWriterLockSlim();
            try
            {
                locker.EnterReadLock();
                byte[] encryptedBytes = File.ReadAllBytes(inputFile);
                byte[] preplacedwordToByteArray = System.Text.Encoding.ASCII.GetBytes(preplacedword);
                //hash the preplacedword with sha256
                preplacedwordToByteArray = SHA256.Create().ComputeHash(preplacedwordToByteArray);
                byte[] encryptedByteArray = GetEncryptedByteArray(encryptedBytes, preplacedwordToByteArray);
                string writeAt = !string.IsNullOrEmpty(outputFile) ? outputFile : inputFile;
                File.WriteAllBytes(writeAt, encryptedByteArray);
                return "encryption succeeded";
            }
            catch (Exception)
            {
                return "encryption failed";
            }
            finally
            {
                locker.ExitReadLock();
            }
        }

19 View Source File : AES.cs
License : MIT License
Project Creator : ren8179

public static string DecryptFile(string inputFile, string outputFile, string preplacedword)
        {
            ReaderWriterLockSlim locker = new ReaderWriterLockSlim();
            try
            {
                locker.EnterReadLock();
                byte[] bytesToBeDecrypted = File.ReadAllBytes(inputFile);
                byte[] preplacedwordBytes = Encoding.ASCII.GetBytes(preplacedword);
                preplacedwordBytes = SHA256.Create().ComputeHash(preplacedwordBytes);
                string writeAt = !string.IsNullOrEmpty(outputFile) ? outputFile : inputFile;
                byte[] bytesDecrypted = GetDecryptedByteArray(bytesToBeDecrypted, preplacedwordBytes);
                File.WriteAllBytes(writeAt, bytesDecrypted);
                return "Decryption succeeded";
            }
            catch (Exception)
            {
                return "Decryption failed";
            }
            finally
            {
                locker.ExitReadLock();
            }
        }

19 View Source File : ConcurrentList.cs
License : MIT License
Project Creator : royben

public void CopyTo(T[] array, int arrayIndex)
        {
            try
            {
                this._lock.EnterReadLock();
                this.InnerList.CopyTo(array, arrayIndex);
            }
            finally
            {
                this._lock.ExitReadLock();
            }
        }

19 View Source File : ConcurrentList.cs
License : MIT License
Project Creator : royben

public int IndexOf(T item)
        {
            try
            {
                this._lock.EnterReadLock();
                return this.InnerList.IndexOf(item);
            }
            finally
            {
                this._lock.ExitReadLock();
            }
        }

19 View Source File : ConcurrentList.cs
License : MIT License
Project Creator : royben

public bool Contains(T item)
        {
            try
            {
                this._lock.EnterReadLock();
                return this.InnerList.Contains(item);
            }
            finally
            {
                this._lock.ExitReadLock();
            }
        }

19 View Source File : FileStreamPool.cs
License : Apache License 2.0
Project Creator : RRQM

internal static bool ReadFile(string path, out string mes, long beginPosition, ByteBlock byteBlock, int offset, int length)
        {
            lockSlim.EnterReadLock();
            try
            {
                if (pathStream.TryGetValue(path, out RRQMStream stream))
                {
                    stream.FileStream.Position = beginPosition;

                    int r = stream.FileStream.Read(byteBlock.Buffer, offset, length);
                    if (r == length)
                    {
                        byteBlock.Position = offset + length;
                        byteBlock.SetLength(offset + length);
                        mes = null;
                        return true;
                    }
                }
                mes = "没有找到该路径下的流文件";
                return false;
            }
            catch (Exception ex)
            {
                mes = ex.Message;
                return false;
            }
            finally
            {
                lockSlim.ExitReadLock();
            }
        }

19 View Source File : Library.cs
License : MIT License
Project Creator : rubenwe

public async Task StoreChangesAsync()
        {
            await Task.Run(() =>
            {
                try
                {
                    _lock.EnterReadLock();
                    var metaData = _previewModels.GetMetaData();
                    
                    _configStore.StoreAsync(metaData, true)
                        .Timed("Writing metadata file")
                        .Wait();
                }
                finally
                {
                    _lock.ExitReadLock();
                }
            });
        }

19 View Source File : ReaderWriterLockSlimExtensions.cs
License : MIT License
Project Creator : rubenwe

public static void Read(this ReaderWriterLockSlim rwLock, Action readAction)
        {
            try
            {
                rwLock.EnterReadLock();
                readAction.Invoke();
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : ReaderWriterLockSlimExtensions.cs
License : MIT License
Project Creator : rubenwe

public static T Read<T>(this ReaderWriterLockSlim rwLock, Func<T> readAction)
        {
            try
            {
                rwLock.EnterReadLock();
                return readAction.Invoke();
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

19 View Source File : JsonFileProvider.cs
License : GNU General Public License v3.0
Project Creator : runeberry

public virtual Task<TFile> LoadAsync<TFile>(string filePath) where TFile : clreplaced
        {
            filePath = Environment.ExpandEnvironmentVariables(filePath);
            TFile dataFile = default;

            this.RWLock.EnterReadLock();

            try
            {
                if (File.Exists(filePath))
                {
                    using var streamReader = File.OpenText(filePath);
                    using var jsonReader = new JsonTextReader(streamReader);

                    dataFile = this.Serializer.Deserialize<TFile>(jsonReader);
                }
            }
            catch (Exception e)
            {
                this.Logger.LogException(e, $"Error loading JSON data from file: {filePath}");
            }
            finally
            {
                this.RWLock.ExitReadLock();
            }

            this.OnDataLoaded(dataFile);

            return Task.FromResult(dataFile);
        }

19 View Source File : Schema.cs
License : MIT License
Project Creator : rwredding

public TMetadata GetMetadata<TMetadata>(string name)
            where TMetadata : IMetadata
        {
            MetadataKey key = new MetadataKey(typeof(TMetadata), name, this.Notation.Comparer);
            ReaderWriterLockSlim slim = this.GetLock<TMetadata>();

            try
            {
                slim.EnterReadLock();

                if (this.entries.TryGetValue(key, out object value))
                    return (TMetadata)value;
            }
            catch (LockRecursionException ex)
            {
                throw new MetadataBuilderException("To mitigate async deadlocks, fetching metadata recursively through ISchema is not supported.", ex);
            }
            finally
            {
                if (slim.IsReadLockHeld)
                    slim.ExitReadLock();
            }


            slim.EnterWriteLock();

            try
            {
                foreach (IMetadataBuilder<TMetadata> metadataBuilder in this.store.OfType<IMetadataBuilder<TMetadata>>())
                {
                    MetadataIdenreplacedy idenreplacedy = new MetadataIdenreplacedy(this, name);
                    MetadataBuilderContext context = new MetadataBuilderContext(idenreplacedy, this);

                    TMetadata metadata = metadataBuilder.GetMetadata(context);

                    if (metadata != null)
                        return metadata;
                }

                return default;
            }
            finally
            {
                if (slim.IsWriteLockHeld)
                    slim.ExitWriteLock();

                this.RemoveLock<TMetadata>();
            }
        }

19 View Source File : ReactContext.cs
License : MIT License
Project Creator : Samsung

public async Task DisposeAsync()
        {
            DispatcherHelpers.replacedertOnDispatcher();

            var clone = default(List<ILifecycleEventListener>);

            _lock.EnterReadLock();
            try
            {
                clone = _lifecycleEventListeners.ToList(/* clone */);
            }
            finally
            {
                _lock.ExitReadLock();
            }

            foreach (var listener in clone)
            {
                listener.OnDestroy();
            }

            var reactInstance = _reactInstance;
            if (reactInstance != null)
            {
                await reactInstance.DisposeAsync().ConfigureAwait(false);
            }

            _lock.Dispose();
        }

19 View Source File : ReactContext.cs
License : MIT License
Project Creator : Samsung

public void OnSuspend()
        {
            DispatcherHelpers.replacedertOnDispatcher();

            var clone = default(List<ILifecycleEventListener>);

            _lock.EnterReadLock();
            try
            {
                clone = _lifecycleEventListeners.ToList(/* clone */);
            }
            finally
            {
                _lock.ExitReadLock();
            }

            foreach (var listener in clone)
            {
                listener.OnSuspend();
            }
        }

19 View Source File : ReactContext.cs
License : MIT License
Project Creator : Samsung

public void OnResume()
        {
            DispatcherHelpers.replacedertOnDispatcher();

            var clone = default(List<ILifecycleEventListener>);

            _lock.EnterReadLock();
            try
            {
                clone = _lifecycleEventListeners.ToList(/* clone */);
            }
            finally
            {
                _lock.ExitReadLock();
            }

            foreach (var listener in clone)
            {
                listener.OnResume();
            }
        }

19 View Source File : ConnectionManager.cs
License : MIT License
Project Creator : SapphireDb

public void CheckExistingConnections()
        {
            Task.Run(() =>
            {
                List<ConnectionBase> connectionsCopy;

                try
                {
                    connectionsLock.EnterReadLock();
                    connectionsCopy = connections.Values.ToList();
                }
                finally
                {
                    connectionsLock.ExitReadLock();
                }

                Parallel.ForEach(connectionsCopy, connection =>
                {
                    if (connection is PollConnection pollConnection)
                    {
                        if (pollConnection.ShouldRemove())
                        {
                            RemoveConnection(pollConnection);
                        }
                    }
                });
            });
        }

19 View Source File : ConnectionManager.cs
License : MIT License
Project Creator : SapphireDb

public ConnectionBase GetConnection(HttpContext context)
        {
            ConnectionBase connection = null;

            string connectionIdHeaderValue = context.Request.Headers["connectionId"];
            
            if (!string.IsNullOrEmpty(connectionIdHeaderValue))
            {
                Guid connectionId = Guid.Parse(connectionIdHeaderValue);

                bool connectionFound;
                
                try
                {
                    connectionsLock.EnterReadLock();
                    connectionFound = connections.TryGetValue(connectionId, out connection);
                }
                finally
                {
                    connectionsLock.ExitReadLock();
                }
                
                if (connectionFound)
                {
                    // Compare user Information of the request and the found connection
                    if (connection.Information.User.Idenreplacedy.IsAuthenticated)
                    {
                        List<Claim> connectionClaims = connection.Information.User.Claims.ToList();
                        List<Claim> requestClaims = context.User.Claims.ToList();

                        if (connectionClaims.Any(connectionClaim =>
                        {
                            return !requestClaims.Any(claim =>
                                claim.Type == connectionClaim.Type && claim.Value == connectionClaim.Value);
                        }))
                        {
                            return null;
                        }
                    }

                    // Compare connection info of request and found connection
                    HttpInformation connectionInfo = connection.Information;

                    if (!connectionInfo.LocalIpAddress.Equals(context.Connection.LocalIpAddress) ||
                        !connectionInfo.LocalPort.Equals(context.Connection.LocalPort) ||
                        !connectionInfo.RemoteIpAddress.Equals(context.Connection.RemoteIpAddress))
                    {
                        return null;
                    }
                }
            }

            return connection;
        }

19 View Source File : MessageSubscriptionManager.cs
License : MIT License
Project Creator : SapphireDb

public List<Subscription> GetTopicSubscriptions(string topic)
        {
            try
            {
                readerWriterLockSlim.EnterReadLock();

                return subscriptions
                    .Where(s => topic.MatchesGlobPattern(s.Key))
                    .SelectMany(s => s.Value)
                    .ToList();
            }
            finally
            {
                readerWriterLockSlim.ExitReadLock();
            }
        }

19 View Source File : SubscriptionManager.cs
License : MIT License
Project Creator : SapphireDb

public Dictionary<PrefilterContainer, List<Subscription>> GetSubscriptions(string contextName, string collectionName)
        {
            try
            {
                readerWriterLockSlim.EnterReadLock();
            
                if (subscriptions.TryGetValue(contextName,
                    out Dictionary<string, Dictionary<PrefilterContainer, List<Subscription>>> subscriptionsOfContext))
                {
                    if (subscriptionsOfContext.TryGetValue(collectionName,
                        out Dictionary<PrefilterContainer, List<Subscription>> subscriptionsOfCollection))
                    {
                        return subscriptionsOfCollection;
                    }
                }
            }
            finally
            {
                readerWriterLockSlim.ExitReadLock();
            }

            return null;
        }

19 View Source File : SubscriptionManager.cs
License : MIT License
Project Creator : SapphireDb

public List<CollectionSubscriptionsContainer> GetSubscriptionsWithInclude(string contextName, string collectionName)
        {
            try
            {
                readerWriterLockSlim.EnterReadLock();

                if (!subscriptions.TryGetValue(contextName, out var contextSubscriptions))
                {
                    return null;
                }

                var includeSubscriptions = contextSubscriptions
                    .Select(collectionSubscriptions =>
                    {
                        return new CollectionSubscriptionsContainer()
                        {
                            CollectionName = collectionSubscriptions.Key,
                            Subscriptions = collectionSubscriptions.Value
                                .Where(equalSubscriptions => equalSubscriptions.Key.HasAffectedIncludePrefilter(collectionName))
                        };
                    })
                    .Where(container => container.Subscriptions.Any())
                    .ToList();
                
                return includeSubscriptions;
            }
            finally
            {
                readerWriterLockSlim.ExitReadLock();
            }
        }

19 View Source File : ConcurrentHashset`1.cs
License : Apache License 2.0
Project Creator : SciSharp

public void UnionWith(IEnumerable<T> other)
        {
            _lock.EnterWriteLock();
            _lock.EnterReadLock();
            try
            {
                hashset.UnionWith(other);
            }
            finally
            {
                if (_lock.IsWriteLockHeld) _lock.ExitWriteLock();
                if (_lock.IsReadLockHeld) _lock.ExitReadLock();
            }
        }

19 View Source File : ConcurrentHashset`1.cs
License : Apache License 2.0
Project Creator : SciSharp

public void IntersectWith(IEnumerable<T> other)
        {
            _lock.EnterWriteLock();
            _lock.EnterReadLock();
            try
            {
                hashset.IntersectWith(other);
            }
            finally
            {
                if (_lock.IsWriteLockHeld) _lock.ExitWriteLock();
                if (_lock.IsReadLockHeld) _lock.ExitReadLock();
            }
        }

19 View Source File : ConcurrentHashset`1.cs
License : Apache License 2.0
Project Creator : SciSharp

public void ExceptWith(IEnumerable<T> other)
        {
            _lock.EnterWriteLock();
            _lock.EnterReadLock();
            try
            {
                hashset.ExceptWith(other);
            }
            finally
            {
                if (_lock.IsWriteLockHeld) _lock.ExitWriteLock();
                if (_lock.IsReadLockHeld) _lock.ExitReadLock();
            }
        }

19 View Source File : ConcurrentHashset`1.cs
License : Apache License 2.0
Project Creator : SciSharp

public void CopyTo(ArraySlice<T> array, int arrayIndex, int count)
        {
            _lock.EnterWriteLock();
            _lock.EnterReadLock();
            try
            {
                //CopyTo<T>(Hashset<T> src, ArraySlice<T> array, int arrayIndex, int count)
                Hashset<T>.CopyTo(hashset, array, arrayIndex, count);
            }
            finally
            {
                if (_lock.IsWriteLockHeld) _lock.ExitWriteLock();
                if (_lock.IsReadLockHeld) _lock.ExitReadLock();
            }
        }

19 View Source File : ObjectSubclassingController.cs
License : GNU General Public License v3.0
Project Creator : scode-cmd

public Type GetType(String clreplacedName) {
      ObjectSubclreplacedInfo info = null;
      mutex.EnterReadLock();
      registeredSubclreplacedes.TryGetValue(clreplacedName, out info);
      mutex.ExitReadLock();

      return info != null
        ? info.TypeInfo.AsType()
        : null;
    }

19 View Source File : ObjectSubclassingController.cs
License : GNU General Public License v3.0
Project Creator : scode-cmd

public bool IsTypeValid(String clreplacedName, Type type) {
      ObjectSubclreplacedInfo subclreplacedInfo = null;

      mutex.EnterReadLock();
      registeredSubclreplacedes.TryGetValue(clreplacedName, out subclreplacedInfo);
      mutex.ExitReadLock();

      return subclreplacedInfo == null
        ? type == typeof(ParseObject)
        : subclreplacedInfo.TypeInfo == type.GetTypeInfo();
    }

19 View Source File : ObjectSubclassingController.cs
License : GNU General Public License v3.0
Project Creator : scode-cmd

public ParseObject Instantiate(String clreplacedName) {
      ObjectSubclreplacedInfo info = null;

      mutex.EnterReadLock();
      registeredSubclreplacedes.TryGetValue(clreplacedName, out info);
      mutex.ExitReadLock();

      return info != null
        ? info.Instantiate()
        : new ParseObject(clreplacedName);
    }

19 View Source File : ObjectSubclassingController.cs
License : GNU General Public License v3.0
Project Creator : scode-cmd

public IDictionary<String, String> GetPropertyMappings(String clreplacedName) {
      ObjectSubclreplacedInfo info = null;
      mutex.EnterReadLock();
      registeredSubclreplacedes.TryGetValue(clreplacedName, out info);
      if (info == null) {
        registeredSubclreplacedes.TryGetValue(parseObjectClreplacedName, out info);
      }
      mutex.ExitReadLock();

      return info.PropertyMappings;
    }

19 View Source File : ReaderWriterLockSlimEx.cs
License : MIT License
Project Creator : sebas77

public void EnterReadLock()           { _slimLock.EnterReadLock(); }

19 View Source File : SubscriberCollection.cs
License : GNU General Public License v3.0
Project Creator : Sebazzz

public IEnumerable<TSubscriber> Gereplacedems() {
            // While we iterate through the queue we need to take note of any dead subscribers 
            var deadSubscribers = new List<Guid>();

            // We need to take a read lock on the queue so at least stuff does not get removed while iterating
            this._subscriberCollectionLock.EnterReadLock();
            try {
                foreach (KeyValuePair<Guid, WeakReference<TSubscriber>> subscriberItem in this._subscribers) {
                    if (!subscriberItem.Value.TryGetTarget(out TSubscriber? subscriber)) {
                        deadSubscribers.Add(subscriberItem.Key);
                    }
                    else {
                        yield return subscriber;
                    }
                }
            }
            finally {
                this._subscriberCollectionLock.ExitReadLock();
            }

            // Remove dead subscribers
            if (deadSubscribers.Count > 0) {
                this._subscriberCollectionLock.EnterWriteLock();

                try {
                    foreach (Guid deadSubscriber in deadSubscribers) {
                        this._subscribers.TryRemove(deadSubscriber, out _);
                    }
                }
                finally {
                    this._subscriberCollectionLock.ExitWriteLock();
                }
            }
        }

19 View Source File : DescriptionDataTable.cs
License : GNU General Public License v3.0
Project Creator : SeeSharpOpenSource

public bool Contains(string replacedemblyName)
        {
            _lock.EnterReadLock();
            bool containsKey = _descriptions.ContainsKey(replacedemblyName);
            _lock.ExitReadLock();
            return containsKey;
        }

19 View Source File : DescriptionDataTable.cs
License : GNU General Public License v3.0
Project Creator : SeeSharpOpenSource

public bool Contains(int componentId)
        {
            _lock.EnterReadLock();
            bool containsKey = _descriptions.Any(item => item.Value.ComponentId == componentId);
            _lock.ExitReadLock();
            return containsKey;
        }

19 View Source File : DescriptionDataTable.cs
License : GNU General Public License v3.0
Project Creator : SeeSharpOpenSource

public IreplacedemblyInfo GetreplacedemblyInfo(string replacedemblyName)
        {
            IreplacedemblyInfo replacedemblyInfo = null;
            _lock.EnterReadLock();

            if (_descriptions.ContainsKey(replacedemblyName))
            {
                replacedemblyInfo = _descriptions[replacedemblyName].replacedembly;
            }
            else if (_refreplacedemblyInfos.ContainsKey(replacedemblyName))
            {
                replacedemblyInfo = _refreplacedemblyInfos[replacedemblyName];
            }
            _lock.ExitReadLock();
            return replacedemblyInfo;
        }

19 View Source File : DescriptionDataTable.cs
License : GNU General Public License v3.0
Project Creator : SeeSharpOpenSource

public ComInterfaceDescription GetComDescription(int componentId)
        {
            _lock.EnterReadLock();
            ComInterfaceDescription description =
                _descriptions.Values.FirstOrDefault(item => item.ComponentId == componentId);
            _lock.ExitReadLock();
            return description;
        }

19 View Source File : DescriptionDataTable.cs
License : GNU General Public License v3.0
Project Creator : SeeSharpOpenSource

public ComInterfaceDescription GetComDescriptionByPath(string path)
        {
            _lock.EnterReadLock();
            ComInterfaceDescription description =
                _descriptions.Values.FirstOrDefault(item => item.replacedembly.Path.Equals(path));
            _lock.ExitReadLock();
            return description;
        }

19 View Source File : OverLapBuffer.cs
License : GNU General Public License v3.0
Project Creator : SeeSharpOpenSource

public TDataType GetLastElement(int offset)
        {
            TDataType dataValue = null;
            _operationLock.EnterReadLock();

            int startIndex = Thread.VolatileRead(ref _startIndex);
            int readIndex = (_nextIndex - offset)%_capacity;
            if (readIndex <= startIndex)
            {
                dataValue = _innerBuffer[readIndex];
            }
            _operationLock.ExitReadLock();

            return dataValue;
        }

19 View Source File : DescriptionDataTable.cs
License : GNU General Public License v3.0
Project Creator : SeeSharpOpenSource

public ComInterfaceDescription GetComDescription(string replacedemblyName)
        {
            ComInterfaceDescription description = null;
            _lock.EnterReadLock();

            if (_descriptions.ContainsKey(replacedemblyName))
            {
                description = _descriptions[replacedemblyName];
            }
            _lock.ExitReadLock();
            return description;
        }

19 View Source File : VariableMapper.cs
License : GNU General Public License v3.0
Project Creator : SeeSharpOpenSource

public object GetParamValue(string variableName, string paramValueStr, ITypeData targetType)
        {
            object value;
            if (_syncVariables.Contains(variableName))
            {
                _syncVarLock.EnterReadLock();
                value = GetParamValue(paramValueStr, this._variables[variableName], targetType);
                _syncVarLock.ExitReadLock();
            }
            else
            {
                value = GetParamValue(paramValueStr, this._variables[variableName], targetType);
            }
            return value;
        }

19 View Source File : DebugManager.cs
License : GNU General Public License v3.0
Project Creator : SeeSharpOpenSource

private void RefreshWatchData(DebugMessage message)
        {
            if (message.WatchData?.Names != null)
            {
                _watchDatas = message.WatchData;
                _hitBreakPointsLock.EnterReadLock();
                try
                {
                    // 如果存在Coroutine被阻塞,则在所有的断点上发送DebugMessage以更新当前节点的值
                    if (_hitBreakPoints.Count > 0)
                    {
                        _watchDatas.Values.Clear();
                        foreach (string watchData in _watchDatas.Names)
                        {
                            string variableName = ModuleUtils.GetVariableNameFromParamValue(watchData);
                            _watchDatas.Values.Add(_context.VariableMapper.GereplacedchDataValue(variableName, watchData));
                        }
                        foreach (StepTaskEnreplacedyBase blockStep in _hitBreakPoints.Values)
                        {
                            if (null == blockStep)
                            {
                               continue;
                            }
                            CallStack breakPoint = blockStep.GetStack();
                            DebugMessage debugMessage = new DebugMessage(MessageNames.BreakPointHitName, _context.SessionId,
                                breakPoint, false)
                            {
                                WatchData = _watchDatas
                            };
                            _context.MessageTransceiver.SendMessage(debugMessage);
                        }
                        _context.LogSession.Print(LogLevel.Debug, _context.SessionId, "Refresh Watch data values.");
                    }
                }
                finally
                {
                    _hitBreakPointsLock.ExitReadLock();
                }
            }
            else
            {
                _watchDatas.Names.Clear();
                _watchDatas.Values.Clear();
            }
        }

19 View Source File : SafeReaderWriterLock.cs
License : Apache License 2.0
Project Creator : sevenTiny

public void Lock()
        {
            locker.EnterReadLock();
        }

19 View Source File : Search.cs
License : MIT License
Project Creator : Smoxer

public bool IsIslandExist(string islandID)
        {
            bool result = false;
            lock_.EnterReadLock();
            try
            {
                if (!Directory.Exists("Reports/Islands" + server + "/"))
                {
                    Directory.CreateDirectory("Reports/Islands" + server + "/");
                }

                result = File.Exists("Reports/Islands" + server + "/" + islandID + ".js");
            }
            finally
            {
                lock_.ExitReadLock();
            }
            return result;
        }

19 View Source File : Search.cs
License : MIT License
Project Creator : Smoxer

public string ReadIsland(string islandID)
        {
            string x = string.Empty;
            lock_.EnterReadLock();
            try
            {
                x = File.ReadAllText("Reports/Islands" + server + "/" + islandID + ".js");
            }
            finally
            {
                lock_.ExitReadLock();
            }
            return x;
        }

19 View Source File : ConcurrentEntityCollection.cs
License : MIT License
Project Creator : SpiceSharp

public bool TryGetEnreplacedy(string name, out IEnreplacedy enreplacedy)
        {
            _lock.EnterReadLock();
            try
            {
                return _enreplacedies.TryGetValue(name, out enreplacedy);
            }
            finally
            {
                _lock.ExitReadLock();
            }
        }

19 View Source File : BehaviorContainerCollection.cs
License : MIT License
Project Creator : SpiceSharp

public virtual BehaviorList<T> GetBehaviorList<T>() where T : IBehavior
        {
            _lock.EnterReadLock();
            try
            {
                var list = new List<T>(_values.Count);
                foreach (var elt in _values)
                {
                    if (elt.TryGetValue(out T value))
                        list.Add(value);
                }
                return new BehaviorList<T>(list.ToArray());
            }
            finally
            {
                _lock.ExitReadLock();
            }
        }

19 View Source File : ConcurrentEntityCollection.cs
License : MIT License
Project Creator : SpiceSharp

public bool Contains(string name)
        {
            _lock.EnterReadLock();
            try
            {
                return _enreplacedies.ContainsKey(name);
            }
            finally
            {
                _lock.ExitReadLock();
            }
        }

19 View Source File : ConcurrentEntityCollection.cs
License : MIT License
Project Creator : SpiceSharp

public IEnumerable<E> ByType<E>() where E : IEnreplacedy
        {
            _lock.EnterReadLock();
            try
            {
                foreach (var enreplacedy in _enreplacedies.Values)
                {
                    if (enreplacedy is E e)
                        yield return e;
                }
            }
            finally
            {
                _lock.ExitReadLock();
            }
        }

See More Examples