internal void ConnectionCompleted(RendererConnection conn) { RenderHost host; lock (threadlock) { host = waiting[conn]; // Retrieve the host associated with this connection waiting.Remove(conn); } if (conn.Success) // Adjust priority based on success or error host.Priority++; else host.Priority--; lock (threadlock) renderHosts[host]++; // Increase the number of available workers on this host again resevent.Set(); // Signal that there is a new worker available }
internal RendererConnection GetConnection() { RenderHost host; while (true) { Monitor.Enter(threadlock); if (AvailableWorkers > 0) { host = renderHosts.Where(p => p.Value > 0) // Select a host with available workers .OrderByDescending(p => p.Key.Priority) // Order by priority .First().Key; // Take the first and best Monitor.Exit(threadlock); break; } else { Monitor.Exit(threadlock); resevent.WaitOne(); // Wait for one to be put in the list } } RendererConnection c = new RendererConnection(host.EndPoint); lock (threadlock) { renderHosts[host]--; // Decease number of available workers on this host waiting.Add(c, host); // Add the connection to the list of running ops } return c; }