/* run through the list and find a worker thread that doesn't have a lot to do right now. This can return null if we aren't yet at the thread count limit and all of the threads are busy.  */
static struct btrfs_worker_thread* next_worker(struct btrfs_workers *workers)
/* run through the list and find a worker thread that doesn't have a lot to do right now. This can return null if we aren't yet at the thread count limit and all of the threads are busy.  */
static struct btrfs_worker_thread* next_worker(struct btrfs_workers *workers)
{
	struct btrfs_worker_thread *worker;
	struct list_head *next;
	int enforce_min;
	enforce_min = (workers->num_workers + workers->num_workers_starting) <
		workers->max_workers;
	if (!list_empty(&workers->idle_list)) {
		next = workers->idle_list.next;
		worker = list_entry(next, struct btrfs_worker_thread,
				    worker_list);
		return worker;
	}
	if (enforce_min || list_empty(&workers->worker_list))
		return NULL;
	next = workers->worker_list.next;
	worker = list_entry(next, struct btrfs_worker_thread, worker_list);
	worker->sequence++;
	if (worker->sequence % workers->idle_thresh == 0)
		list_move_tail(next, &workers->worker_list);
	return worker;
}