/* Kernel thread which handles packets that are completed. This way the packet's "complete" function is asynchronously run in process context. Only packets which have a "complete" function may be sent here.  */
static int hpsbpkt_thread(void *__hi)
/* Kernel thread which handles packets that are completed. This way the packet's "complete" function is asynchronously run in process context. Only packets which have a "complete" function may be sent here.  */
static int hpsbpkt_thread(void *__hi)
{
	struct hpsb_packet *packet, *p;
	struct list_head tmp;
	int may_schedule;
	while (!kthread_should_stop()) {
		INIT_LIST_HEAD(&tmp);
		spin_lock_irq(&pending_packets_lock);
		list_splice_init(&hpsbpkt_queue, &tmp);
		spin_unlock_irq(&pending_packets_lock);
		list_for_each_entry_safe(packet, p, &tmp, queue) {
			list_del_init(&packet->queue);
			packet->complete_routine(packet->complete_data);
		}
		set_current_state(TASK_INTERRUPTIBLE);
		spin_lock_irq(&pending_packets_lock);
		may_schedule = list_empty(&hpsbpkt_queue);
		spin_unlock_irq(&pending_packets_lock);
		if (may_schedule)
			schedule();
		__set_current_state(TASK_RUNNING);
	}
	return 0;
}