Beispiel #1
0
        /// <summary>
        /// The code-generation thread.
        /// </summary>
        private void DoWork()
        {
            var detectedMethods = new HashSet <MethodBase>();

            for (; ;)
            {
                ProcessingEntry current;
                lock (processingSyncObject)
                {
                    while (processing.Count < 1 & running)
                    {
                        Monitor.Wait(processingSyncObject);
                    }

                    if (!running)
                    {
                        break;
                    }

                    ++activeThreads;
                    current = processing.Pop();
                }

                Debug.Assert(
                    codeGenerationPhase != null,
                    "Invalid processing state");

                detectedMethods.Clear();
                codeGenerationPhase.GenerateCodeInternal(
                    current.Method,
                    current.IsExternalRequest,
                    detectedMethods,
                    out Method method);
                current.SetResult(method);

                // Check dependencies
                lock (processingSyncObject)
                {
                    --activeThreads;

                    foreach (var detectedMethod in detectedMethods)
                    {
                        processing.Push(new ProcessingEntry(detectedMethod, null));
                    }

                    if (detectedMethods.Count > 0)
                    {
                        Monitor.PulseAll(processingSyncObject);
                    }
                    else
                    {
                        if (activeThreads == 0 && processing.Count < 1)
                        {
                            driverNotifier.Set();
                        }
                    }
                }
            }
        }
Beispiel #2
0
        private void DoWork()
        {
            var detectedMethods = new Dictionary <MethodBase, CompilationStackLocation>();

            for (; ;)
            {
                ProcessingEntry current;
                lock (processingSyncObject)
                {
                    while (processing.Count < 1 & running)
                    {
                        Monitor.Wait(processingSyncObject);
                    }

                    if (!running)
                    {
                        break;
                    }

                    ++activeThreads;
                    current = processing.Pop();
                }

                Debug.Assert(
                    codeGenerationPhase != null,
                    "Invalid processing state");

                detectedMethods.Clear();
                try
                {
                    codeGenerationPhase.GenerateCodeInternal(
                        current.Method,
                        current.IsExternalRequest,
                        current.CompilationStackLocation,
                        detectedMethods,
                        out Method method);
                    current.SetResult(method);
                }
                catch (Exception e)
                {
                    codeGenerationPhase.RecordException(e);
                    detectedMethods.Clear();
                }

                // Check dependencies
                lock (processingSyncObject)
                {
                    --activeThreads;

                    try
                    {
                        foreach (var detectedMethod in detectedMethods)
                        {
                            processing.Push(new ProcessingEntry(
                                                detectedMethod.Key,
                                                detectedMethod.Value,
                                                null));
                        }
                    }
                    catch (Exception e)
                    {
                        codeGenerationPhase.RecordException(e);
                        detectedMethods.Clear();
                        processing.Clear();
                    }

                    if (detectedMethods.Count > 0)
                    {
                        Monitor.PulseAll(processingSyncObject);
                    }
                    else
                    {
                        if (activeThreads == 0 && processing.Count < 1)
                        {
                            driverNotifier.Set();
                        }
                    }
                }
            }
        }