private bool EnqueueAfterDequeue(ThreadLocalAssemblyContext threadLocalAssemblyContext, AssemblyContext assemblyContext)
        {
            if (threadLocalAssemblyContext.Value != assemblyContext)
            {
                throw new InvalidOperationException(
                          "The specified AssemblyContext has been dequeued on a different thread. "
                          + "An AssemblyContext must be enqueued on the same thread it was dequeued from.");
            }

            threadLocalAssemblyContext.DecrementCount();

            if (threadLocalAssemblyContext.Count == 0)
            {
                try
                {
                    _assemblyContextPool.Enqueue(assemblyContext);
                }
                catch
                {
                    threadLocalAssemblyContext.IncrementCount();
                    throw;
                }
            }

            return(threadLocalAssemblyContext.Count == 0);
        }
예제 #2
0
 private Lazy <Type> CreateAssembledType(AssembledTypeID typeID)
 {
     return(new Lazy <Type> (
                () =>
     {
         var assemblyContext = _assemblyContextPool.Dequeue();
         try
         {
             var result = _typeAssembler.AssembleType(typeID, assemblyContext.ParticipantState, assemblyContext.MutableTypeBatchCodeGenerator);
             AddAdditionalTypesToCache(result.AdditionalTypes);
             return result.Type;
         }
         finally
         {
             _assemblyContextPool.Enqueue(assemblyContext);
         }
     },
                LazyThreadSafetyMode.ExecutionAndPublication));
 }
예제 #3
0
        public string[] FlushCodeToDisk(params CustomAttributeDeclaration[] assemblyAttributes)
        {
            ArgumentUtility.CheckNotNull("assemblyAttributes", assemblyAttributes);

            AssemblyContext[] assemblyContexts = _assemblyContextPool.DequeueAll();
            try
            {
                return(assemblyContexts
                       .AsParallel()
                       .Select(assemblyContext => FlushCodeToDisk(assemblyAttributes, assemblyContext))
                       .Where(path => path != null)
                       .ToArray());
            }
            finally
            {
                foreach (var assemblyContext in assemblyContexts)
                {
                    _assemblyContextPool.Enqueue(assemblyContext);
                }
            }
        }