System.Text.RegularExpressions.ExclusiveReference.Release C# (CSharp) Method

Release() private method

private Release ( Object obj ) : void
obj Object
return void
        internal void Release(Object obj) {
            if (obj == null)
                throw new ArgumentNullException("obj");

            // if this reference owns the lock, release it

            if (_obj == obj) {
                _obj = null;
                _locked = 0;
                return;
            }

            // if no reference owns the lock, try to cache this reference

            if (_obj == null) {
                // try to obtain the lock

                if (0 == Interlocked.Exchange(ref _locked, 1)) {
                    // if there's really no reference, cache this reference

                    if (_ref == null)
                        _ref = (RegexRunner) obj;

                    // release the lock

                    _locked = 0;
                    return;
                }
            }
        }
    }

Usage Example

示例#1
0
文件: Regex.cs 项目: xuanmu/corefx
        /*
         * Internal worker called by all the public APIs
         */
        internal Match Run(bool quick, int prevlen, string input, int beginning, int length, int startat)
        {
            Match       match;
            RegexRunner runner = null;

            if (startat < 0 || startat > input.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(startat), SR.BeginIndexNotNegative);
            }

            if (length < 0 || length > input.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(length), SR.LengthNotNegative);
            }

            // There may be a cached runner; grab ownership of it if we can.

            runner = (RegexRunner)_runnerref.Get();

            // Create a RegexRunner instance if we need to

            if (runner == null)
            {
                if (factory != null)
                {
                    runner = factory.CreateInstance();
                }
                else
                {
                    runner = new RegexInterpreter(_code, UseOptionInvariant() ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture);
                }
            }

            try
            {
                // Do the scan starting at the requested position
                match = runner.Scan(this, input, beginning, beginning + length, startat, prevlen, quick, internalMatchTimeout);
            }
            finally
            {
                // Release or fill the cache slot
                _runnerref.Release(runner);
            }

#if DEBUG
            if (Debug && match != null)
            {
                match.Dump();
            }
#endif
            return(match);
        }
All Usage Examples Of System.Text.RegularExpressions.ExclusiveReference::Release
ExclusiveReference