예제 #1
0
        public IMuxerRegistration Register(FilePath file, FileLogSettings settings, WeakReference initiator)
        {
            while (true)
            {
                if (states.TryGetValue(file, out var currentState))
                {
                    if (states.TryUpdate(file, currentState.AddParticipant(initiator), currentState))
                    {
                        break;
                    }
                }
                else
                {
                    var initialState = FileState.CreateInitial(factory.Create(settings), initiator);

                    if (states.TryAdd(file, initialState))
                    {
                        break;
                    }
                }
            }

            var registration = new MuxerRegistration(states, registrations, file, initiator);

            registrations.TryAdd(registration, registration);

            return(registration);
        }