public AssemblyContext[] DequeueAll() { var data = _threadLocalCache.Value; if (data is ThreadLocalAssemblyContext) { throw new InvalidOperationException( "DequeueAll() cannot be invoked from the same thread as Dequeue() until all dequeued AssemblyContext have been returned to the pool."); } if (data is HashSet <AssemblyContext> ) { throw new InvalidOperationException( "DequeueAll() cannot be invoked from the same thread as a previous call to DequeueAll() " + "until all dequeued AssemblyContext have been returned to the pool."); } Assertion.IsNull(data, "No information should be available for thread ID '{0}'.", Thread.CurrentThread.ManagedThreadId); var assemblyContexts = _assemblyContextPool.DequeueAll(); _threadLocalCache.Value = new HashSet <AssemblyContext> (assemblyContexts); return(assemblyContexts); }
public AssemblyContext[] DequeueAll() { var data = CallContext.GetData(_instanceID); if (data is ThreadLocalAssemblyContext) { throw new InvalidOperationException( "DequeueAll() cannot be invoked from the same thread as Dequeue() until all dequeued AssemblyContext have been returned to the pool."); } if (data is HashSet <AssemblyContext> ) { throw new InvalidOperationException( "DequeueAll() cannot be invoked from the same thread as a previous call to DequeueAll() " + "until all dequeued AssemblyContext have been returned to the pool."); } Assertion.IsNull(data, "No information should be available for pool-ID '{0}'.", _instanceID); var assemblyContexts = _assemblyContextPool.DequeueAll(); CallContext.SetData(_instanceID, new HashSet <AssemblyContext> (assemblyContexts)); return(assemblyContexts); }
public void LoadTypes(IEnumerable <Type> generatedTypes) { ArgumentUtility.CheckNotNull("generatedTypes", generatedTypes); // Dequeuing all assembly contexts is not required for consistent loading of types // but helps to ensure that the pre-generated types are preferred. var assemblyContexts = _assemblyContextPool.DequeueAll(); try { generatedTypes .AsParallel() .WithDegreeOfParallelism(assemblyContexts.Length) .ForAll( type => { if (_typeAssembler.IsAssembledType(type)) { LoadAssembledType(type); } else { LoadAdditionalType(type); } }); } finally { foreach (var assemblyContext in assemblyContexts) { _assemblyContextPool.Enqueue(assemblyContext); } } }
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); } } }