Index: kernel/generic/src/synch/workqueue.c
===================================================================
--- kernel/generic/src/synch/workqueue.c	(revision 1b20da07baaa3e3c424f62c927274e676e4295cd)
+++ kernel/generic/src/synch/workqueue.c	(revision 34e1206ec4dc79f0592077e3ee270fba91d1eb9d)
@@ -59,17 +59,17 @@
 	 */
 	IRQ_SPINLOCK_DECLARE(lock);
-	
+
 	/* Activates a worker if new work arrives or if shutting down the queue. */
 	condvar_t activate_worker;
-	
+
 	/* Queue of work_items ready to be dispatched. */
 	list_t queue;
-	
+
 	/* List of worker threads. */
 	list_t workers;
-	
+
 	/* Number of work items queued. */
 	size_t item_cnt;
-	
+
 	/* Indicates the work queue is shutting down. */
 	bool stopping;
@@ -84,10 +84,10 @@
 	/* Number of blocked workers sleeping in work func() (ie not idle). */
 	size_t blocked_worker_cnt;
-	
+
 	/* Number of pending signal_worker_op() operations. */
 	size_t pending_op_cnt;
-	
+
 	link_t nb_link;
-	
+
 #ifdef CONFIG_DEBUG
 	/* Magic cookie for integrity checks. Immutable. Accessed without lock. */
@@ -105,5 +105,5 @@
 /** Max number of work items per active worker before a new worker is activated.*/
 static const size_t max_items_per_worker = 8;
-	
+
 /** System wide work queue. */
 static struct work_queue g_work_queue;
@@ -157,10 +157,10 @@
 	 */
 	booting = false;
-	
+
 	nonblock_init();
-	
+
 	if (!add_worker(&g_work_queue))
 		panic("Could not create a single global work queue worker!\n");
-	
+
 }
 
@@ -174,5 +174,5 @@
 	/* Maximum concurrency without slowing down the system. */
 	max_concurrent_workers = max(2, config.cpu_count);
-	
+
 	workq_preinit(&g_work_queue, "kworkq");
 }
@@ -188,5 +188,5 @@
 {
 	struct work_queue *workq = malloc(sizeof(struct work_queue), 0);
-	
+
 	if (workq) {
 		if (workq_init(workq, name)) {
@@ -194,8 +194,8 @@
 			return workq;
 		}
-		
+
 		free(workq);
 	}
-	
+
 	return NULL;
 }
@@ -205,5 +205,5 @@
 {
 	assert(!workq_corrupted(workq));
-	
+
 	irq_spinlock_lock(&workq->lock, true);
 	bool stopped = workq->stopping;
@@ -212,5 +212,5 @@
 #endif
 	irq_spinlock_unlock(&workq->lock, true);
-	
+
 	if (!stopped) {
 		workq_stop(workq);
@@ -218,9 +218,9 @@
 		assert(0 == running_workers);
 	}
-	
+
 #ifdef CONFIG_DEBUG
 	workq->cookie = 0;
 #endif
-	
+
 	free(workq);
 }
@@ -232,20 +232,20 @@
 	workq->cookie = WORKQ_MAGIC;
 #endif
-	
+
 	irq_spinlock_initialize(&workq->lock, name);
 	condvar_initialize(&workq->activate_worker);
-	
+
 	list_initialize(&workq->queue);
 	list_initialize(&workq->workers);
-	
+
 	workq->item_cnt = 0;
 	workq->stopping = false;
 	workq->name = name;
-	
+
 	workq->cur_worker_cnt = 1;
 	workq->idle_worker_cnt = 0;
 	workq->activate_pending = 0;
 	workq->blocked_worker_cnt = 0;
-	
+
 	workq->pending_op_cnt = 0;
 	link_initialize(&workq->nb_link);
@@ -270,16 +270,16 @@
 	thread_t *thread = thread_create(worker_thread, workq, TASK,
 		THREAD_FLAG_NONE, workq->name);
-	
+
 	if (!thread) {
 		irq_spinlock_lock(&workq->lock, true);
-		
+
 		/* cur_worker_cnt proactively increased in signal_worker_logic() .*/
 		assert(0 < workq->cur_worker_cnt);
 		--workq->cur_worker_cnt;
-		
+
 		irq_spinlock_unlock(&workq->lock, true);
 		return false;
 	}
-	
+
 	/* Respect lock ordering. */
 	irq_spinlock_lock(&thread->lock, true);
@@ -290,8 +290,8 @@
 	if (!workq->stopping) {
 		success = true;
-		
+
 		/* Try to distribute workers among cpus right away. */
 		unsigned int cpu_id = (workq->cur_worker_cnt) % config.cpu_active;
-		
+
 		if (!cpus[cpu_id].active)
 			cpu_id = CPU->id;
@@ -312,10 +312,10 @@
 		 */
 		success = false;
-		
+
 		/* cur_worker_cnt proactively increased in signal_worker() .*/
 		assert(0 < workq->cur_worker_cnt);
 		--workq->cur_worker_cnt;
 	}
-	
+
 	irq_spinlock_unlock(&workq->lock, false);
 	irq_spinlock_unlock(&thread->lock, true);
@@ -324,7 +324,7 @@
 		thread_interrupt(thread);
 	}
-		
+
 	thread_ready(thread);
-	
+
 	return success;
 }
@@ -337,5 +337,5 @@
 {
 	assert(!workq_corrupted(workq));
-	
+
 	interrupt_workers(workq);
 	wait_for_workers(workq);
@@ -350,8 +350,8 @@
 	assert(!workq->stopping);
 	workq->stopping = true;
-	
+
 	/* Respect lock ordering - do not hold workq->lock during broadcast. */
 	irq_spinlock_unlock(&workq->lock, true);
-	
+
 	condvar_broadcast(&workq->activate_worker);
 }
@@ -361,7 +361,7 @@
 {
 	assert(!PREEMPTION_DISABLED);
-	
+
 	irq_spinlock_lock(&workq->lock, true);
-	
+
 	list_foreach_safe(workq->workers, cur_worker, next_worker) {
 		thread_t *worker = list_get_instance(cur_worker, thread_t, workq_link);
@@ -370,22 +370,22 @@
 		/* Wait without the lock. */
 		irq_spinlock_unlock(&workq->lock, true);
-		
+
 		thread_join(worker);
 		thread_detach(worker);
-		
+
 		irq_spinlock_lock(&workq->lock, true);
 	}
-	
+
 	assert(list_empty(&workq->workers));
-	
+
 	/* Wait for deferred add_worker_op(), signal_worker_op() to finish. */
 	while (0 < workq->cur_worker_cnt || 0 < workq->pending_op_cnt) {
 		irq_spinlock_unlock(&workq->lock, true);
-		
+
 		scheduler();
-		
+
 		irq_spinlock_lock(&workq->lock, true);
 	}
-	
+
 	irq_spinlock_unlock(&workq->lock, true);
 }
@@ -422,5 +422,5 @@
  *                  until func() is entered.
  * @param func      User supplied function to invoke in a worker thread.
- 
+
  * @return false if work queue is shutting down; function is not
  *               queued for further processing.
@@ -442,5 +442,5 @@
  *                  until func() is entered.
  * @param func      User supplied function to invoke in a worker thread.
- 
+
  * @return false if work queue is shutting down; function is not
  *               queued for further processing.
@@ -467,5 +467,5 @@
  * @param func      User supplied function to invoke in a worker thread.
  * @param can_block May adding this work item block?
- 
+
  * @return false if work queue is shutting down; function is not
  *               queued for further processing.
@@ -476,10 +476,10 @@
 {
 	assert(!workq_corrupted(workq));
-	
+
 	bool success = true;
 	signal_op_t signal_op = NULL;
-	
+
 	irq_spinlock_lock(&workq->lock, true);
-	
+
 	if (workq->stopping) {
 		success = false;
@@ -489,5 +489,5 @@
 		++workq->item_cnt;
 		success = true;
-		
+
 		if (!booting) {
 			signal_op = signal_worker_logic(workq, can_block);
@@ -499,5 +499,5 @@
 		}
 	}
-	
+
 	irq_spinlock_unlock(&workq->lock, true);
 
@@ -505,5 +505,5 @@
 		signal_op(workq);
 	}
-	
+
 	return success;
 }
@@ -515,5 +515,5 @@
 	work_item->cookie = WORK_ITEM_MAGIC;
 #endif
-	
+
 	link_initialize(&work_item->queue_link);
 	work_item->func = func;
@@ -524,17 +524,17 @@
 {
 	assert(irq_spinlock_locked(&workq->lock));
-	
+
 	/* Workers blocked are sleeping in the work function (ie not idle). */
 	assert(workq->blocked_worker_cnt <= workq->cur_worker_cnt);
 	/* Idle workers are waiting for more work to arrive in condvar_wait. */
 	assert(workq->idle_worker_cnt <= workq->cur_worker_cnt);
-	
+
 	/* Idle + blocked workers == sleeping worker threads. */
 	size_t sleeping_workers = workq->blocked_worker_cnt + workq->idle_worker_cnt;
-	
+
 	assert(sleeping_workers	<= workq->cur_worker_cnt);
 	/* Workers pending activation are idle workers not yet given a time slice. */
 	assert(workq->activate_pending <= workq->idle_worker_cnt);
-	
+
 	/*
 	 * Workers actively running the work func() this very moment and
@@ -553,5 +553,5 @@
 {
 	assert(irq_spinlock_locked(&workq->lock));
-	
+
 	/*
 	 * Workers actively running the work func() and are neither blocked nor
@@ -578,5 +578,5 @@
 
 	condvar_signal(&workq->activate_worker);
-	
+
 	irq_spinlock_lock(&workq->lock, true);
 	assert(0 < workq->pending_op_cnt);
@@ -597,5 +597,5 @@
 	assert(!workq_corrupted(workq));
 	assert(irq_spinlock_locked(&workq->lock));
-	
+
 	/* Only signal workers if really necessary. */
 	signal_op_t signal_op = NULL;
@@ -630,5 +630,5 @@
 			bool need_worker = (active < max_concurrent_workers)
 				&& (workq->cur_worker_cnt < max_worker_cnt);
-			
+
 			if (need_worker && can_block) {
 				signal_op = add_worker_op;
@@ -641,5 +641,5 @@
 				++workq->cur_worker_cnt;
 			}
-			
+
 			/*
 			 * We cannot create a new worker but we need one desperately
@@ -648,5 +648,5 @@
 			if (need_worker && !can_block && 0 == active) {
 				assert(0 == workq->idle_worker_cnt);
-				
+
 				irq_spinlock_lock(&nonblock_adder.lock, true);
 
@@ -667,5 +667,5 @@
 		signal_op = NULL;
 	}
-	
+
 	return signal_op;
 }
@@ -682,10 +682,10 @@
 		return;
 	}
-	
+
 	assert(arg != NULL);
-	
+
 	struct work_queue *workq = arg;
 	work_t *work_item;
-	
+
 	while (dequeue_work(workq, &work_item)) {
 		/* Copy the func field so func() can safely free work_item. */
@@ -700,7 +700,7 @@
 {
 	assert(!workq_corrupted(workq));
-	
+
 	irq_spinlock_lock(&workq->lock, true);
-	
+
 	/* Check if we should exit if load is low. */
 	if (!workq->stopping && worker_unnecessary(workq)) {
@@ -710,15 +710,15 @@
 		list_remove(&THREAD->workq_link);
 		irq_spinlock_unlock(&workq->lock, true);
-		
+
 		thread_detach(THREAD);
 		return false;
 	}
-	
+
 	bool stop = false;
-	
+
 	/* Wait for work to arrive. */
 	while (list_empty(&workq->queue) && !workq->stopping) {
 		cv_wait(workq);
-		
+
 		if (0 < workq->activate_pending)
 			--workq->activate_pending;
@@ -729,5 +729,5 @@
 		link_t *work_link = list_first(&workq->queue);
 		*pwork_item = list_get_instance(work_link, work_t, queue_link);
-		
+
 #ifdef CONFIG_DEBUG
 		assert(!work_item_corrupted(*pwork_item));
@@ -736,5 +736,5 @@
 		list_remove(work_link);
 		--workq->item_cnt;
-		
+
 		stop = false;
 	} else {
@@ -744,7 +744,7 @@
 		stop = true;
 	}
-	
+
 	irq_spinlock_unlock(&workq->lock, true);
-	
+
 	return !stop;
 }
@@ -754,5 +754,5 @@
 {
 	assert(irq_spinlock_locked(&workq->lock));
-	
+
 	/* No work is pending. We don't need too many idle threads. */
 	if (list_empty(&workq->queue)) {
@@ -775,8 +775,8 @@
 	++workq->idle_worker_cnt;
 	THREAD->workq_idling = true;
-	
+
 	/* Ignore lock ordering just here. */
 	assert(irq_spinlock_locked(&workq->lock));
-	
+
 	_condvar_wait_timeout_irq_spinlock(&workq->activate_worker,
 		&workq->lock, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE);
@@ -784,5 +784,5 @@
 	assert(!workq_corrupted(workq));
 	assert(irq_spinlock_locked(&workq->lock));
-	
+
 	THREAD->workq_idling = false;
 	--workq->idle_worker_cnt;
@@ -803,8 +803,8 @@
 		assert(THREAD != thread);
 		assert(!workq_corrupted(thread->workq));
-		
+
 		/* Protected by thread->lock */
 		thread->workq_blocked = false;
-		
+
 		irq_spinlock_lock(&thread->workq->lock, true);
 		--thread->workq->blocked_worker_cnt;
@@ -823,16 +823,16 @@
 		assert(!THREAD->workq_blocked);
 		assert(!workq_corrupted(THREAD->workq));
-		
+
 		THREAD->workq_blocked = true;
-		
+
 		irq_spinlock_lock(&THREAD->workq->lock, false);
 
 		++THREAD->workq->blocked_worker_cnt;
-		
+
 		bool can_block = false;
 		signal_op_t op = signal_worker_logic(THREAD->workq, can_block);
-		
+
 		irq_spinlock_unlock(&THREAD->workq->lock, false);
-		
+
 		if (op) {
 			assert(add_worker_noblock_op == op || signal_worker_op == op);
@@ -856,7 +856,7 @@
 	const char *load_str = worker_surplus ? "decreasing" :
 		(0 < workq->activate_pending) ? "increasing" : "stable";
-	
+
 	irq_spinlock_unlock(&workq->lock, true);
-	
+
 	printf(
 		"Configuration: max_worker_cnt=%zu, min_worker_cnt=%zu,\n"
@@ -893,12 +893,12 @@
 
 	irq_spinlock_lock(&info->lock, true);
-	
+
 	while (list_empty(&info->work_queues) && !stop) {
 		errno_t ret = _condvar_wait_timeout_irq_spinlock(&info->req_cv,
 			&info->lock, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_INTERRUPTIBLE);
-		
+
 		stop = (ret == EINTR);
 	}
-	
+
 	if (!stop) {
 		*pworkq = list_get_instance(list_first(&info->work_queues),
@@ -906,10 +906,10 @@
 
 		assert(!workq_corrupted(*pworkq));
-		
+
 		list_remove(&(*pworkq)->nb_link);
 	}
-	
+
 	irq_spinlock_unlock(&info->lock, true);
-	
+
 	return !stop;
 }
@@ -919,5 +919,5 @@
 	nonblock_adder_t *info = arg;
 	struct work_queue *workq;
-	
+
 	while (dequeue_add_req(info, &workq)) {
 		add_worker(workq);
@@ -931,8 +931,8 @@
 	condvar_initialize(&nonblock_adder.req_cv);
 	list_initialize(&nonblock_adder.work_queues);
-	
+
 	nonblock_adder.thread = thread_create(thr_nonblock_add_worker,
 		&nonblock_adder, TASK, THREAD_FLAG_NONE, "kworkq-nb");
-	
+
 	if (nonblock_adder.thread) {
 		thread_ready(nonblock_adder.thread);
