Lucene.Net.Randomized.RandomizedContext.Context C# (CSharp) Method

Context() private static method

private static Context ( Lucene.Net.Support.ThreadClass thread ) : RandomizedContext
thread Lucene.Net.Support.ThreadClass
return RandomizedContext
        private static RandomizedContext Context(ThreadClass thread)
        {
            var group = thread.Instance.GetThreadGroup();

            RandomizedContext context;

            lock (globalLock)
            {
                while (true)
                {
                    context = contexts[group];
                    if (context == null && group.Parent != null)
                        group = group.Parent;
                    else
                        break;
                }

                // TODO: revisit
                if (context == null)
                {
                    context = contexts[group] = new RandomizedContext(group, null, null);
                }
            }

            if (context == null)
            {
                // TODO: revisit
                var message = "No context information for thread," + thread.Name + ". " +
                            "Is this thread running under a " + typeof(RandomizedRunner).Name + " context? ";

                throw new IllegalStateException(message);
            }

            lock (context.contextLock)
            {
                if (!context.threadResources.ContainsKey(thread))
                {
                    var resources = new ThreadResources();

                    //resources.Queue.Enqueue(context.runner.Randomness.Clone(thread));

                    context.threadResources.Add(thread, resources);
                }
            }

            return context;
        }