diff --git a/Implab/AbstractEvent.cs b/Implab/AbstractEvent.cs --- a/Implab/AbstractEvent.cs +++ b/Implab/AbstractEvent.cs @@ -160,8 +160,12 @@ namespace Implab { if (slot < RESERVED_HANDLERS_COUNT) { - if (slot == 0) - Interlocked.CompareExchange(ref m_handlers, new THandler[RESERVED_HANDLERS_COUNT], null); + if (slot == 0) { + m_handlers = new THandler[RESERVED_HANDLERS_COUNT]; + } else { + while (m_handlers == null) + Thread.MemoryBarrier(); + } m_handlers[slot] = handler; diff --git a/Implab/Parsing/CDFADefinition.cs b/Implab/Parsing/CDFADefinition.cs --- a/Implab/Parsing/CDFADefinition.cs +++ b/Implab/Parsing/CDFADefinition.cs @@ -11,10 +11,8 @@ } public CDFADefinition Optimize() { - var optimized = new CDFADefinition(new CharAlphabet()); - - Optimize(optimized, m_alphabet, optimized.Alphabet); - return optimized; + + return (CDFADefinition)Optimize(alphabet => new CDFADefinition((CharAlphabet)alphabet), m_alphabet, new CharAlphabet()); } public void PrintDFA() { diff --git a/Implab/Parsing/DFADefinition.cs b/Implab/Parsing/DFADefinition.cs --- a/Implab/Parsing/DFADefinition.cs +++ b/Implab/Parsing/DFADefinition.cs @@ -66,8 +66,8 @@ namespace Implab.Parsing { m_states[s1].transitions[symbol] = s2; } - public void Optimize(IDFADefinition minimalDFA,IAlphabet sourceAlphabet, IAlphabet minimalAlphabet) { - Safe.ArgumentNotNull(minimalDFA, "minimalDFA"); + protected IDFADefinition Optimize(Func, IDFADefinition> dfaFactory,IAlphabet sourceAlphabet, IAlphabet minimalAlphabet) { + Safe.ArgumentNotNull(dfaFactory, "dfaFactory"); Safe.ArgumentNotNull(minimalAlphabet, "minimalAlphabet"); var setComparer = new CustomEqualityComparer>( @@ -211,6 +211,8 @@ namespace Implab.Parsing { // построение автомата + var minimalDFA = dfaFactory(minimalAlphabet); + var states = new int[ optimalMap.Length ]; states[0] = UNREACHEBLE_STATE; @@ -237,6 +239,7 @@ namespace Implab.Parsing { } } + return minimalDFA; } public void PrintDFA(IAlphabet alphabet) { diff --git a/Implab/Parsing/EDFADefinition.cs b/Implab/Parsing/EDFADefinition.cs --- a/Implab/Parsing/EDFADefinition.cs +++ b/Implab/Parsing/EDFADefinition.cs @@ -18,10 +18,8 @@ namespace Implab.Parsing { } public EDFADefinition Optimize() { - var optimized = new EDFADefinition(new EnumAlphabet()); - Optimize(optimized, m_alphabet, optimized.Alphabet); - - return optimized; + + return (EDFADefinition)Optimize(alphabet => new EDFADefinition((EnumAlphabet)alphabet), m_alphabet, new EnumAlphabet()); } public void PrintDFA() {