public IOThread ChooseIOThread(long affinity)
{
if (m_ioThreads.Count == 0)
return null;
// Find the I/O thread with minimum load.
int minLoad = -1;
IOThread selectedIOThread = null;
for (int i = 0; i != m_ioThreads.Count; i++)
{
var ioThread = m_ioThreads[i];
if (affinity == 0 || (affinity & (1L << i)) > 0)
{
if (selectedIOThread == null || ioThread.Load < minLoad)
{
minLoad = ioThread.Load;
selectedIOThread = ioThread;
}
}
}
return selectedIOThread;
}