Index: generic/src/proc/scheduler.c
===================================================================
--- generic/src/proc/scheduler.c	(revision 169c408f8774661800aa0a9685c9914cbb5a974c)
+++ generic/src/proc/scheduler.c	(revision c4e8ed9d860723e9a528a63a1c23c93516a1e0ba)
@@ -117,5 +117,5 @@
  *
  */
-struct thread *find_best_thread(void)
+static struct thread *find_best_thread(void)
 {
 	thread_t *t;
@@ -223,5 +223,5 @@
  *
  */
-void relink_rq(int start)
+static void relink_rq(int start)
 {
 	link_t head;
@@ -255,4 +255,144 @@
 
 
+/** Scheduler stack switch wrapper
+ *
+ * Second part of the scheduler() function
+ * using new stack. Handling the actual context
+ * switch to a new thread.
+ *
+ */
+static void scheduler_separated_stack(void)
+{
+	int priority;
+
+	ASSERT(CPU != NULL);
+
+	if (THREAD) {
+		switch (THREAD->state) {
+		    case Running:
+			THREAD->state = Ready;
+			spinlock_unlock(&THREAD->lock);
+			thread_ready(THREAD);
+			break;
+
+		    case Exiting:
+			frame_free((__address) THREAD->kstack);
+			if (THREAD->ustack) {
+				frame_free((__address) THREAD->ustack);
+			}
+
+			/*
+			 * Detach from the containing task.
+			 */
+			spinlock_lock(&TASK->lock);
+			list_remove(&THREAD->th_link);
+			spinlock_unlock(&TASK->lock);
+
+			spinlock_unlock(&THREAD->lock);
+    
+			spinlock_lock(&threads_lock);
+			list_remove(&THREAD->threads_link);
+			spinlock_unlock(&threads_lock);
+
+			spinlock_lock(&CPU->lock);
+			if(CPU->fpu_owner==THREAD) CPU->fpu_owner=NULL;
+			spinlock_unlock(&CPU->lock);
+
+			free(THREAD);
+
+			break;
+    
+		    case Sleeping:
+			/*
+			 * Prefer the thread after it's woken up.
+			 */
+			THREAD->priority = -1;
+
+			/*
+			 * We need to release wq->lock which we locked in waitq_sleep().
+			 * Address of wq->lock is kept in THREAD->sleep_queue.
+			 */
+			spinlock_unlock(&THREAD->sleep_queue->lock);
+
+			/*
+			 * Check for possible requests for out-of-context invocation.
+			 */
+			if (THREAD->call_me) {
+				THREAD->call_me(THREAD->call_me_with);
+				THREAD->call_me = NULL;
+				THREAD->call_me_with = NULL;
+			}
+
+			spinlock_unlock(&THREAD->lock);
+
+			break;
+
+		    default:
+			/*
+			 * Entering state is unexpected.
+			 */
+			panic("tid%d: unexpected state %s\n", THREAD->tid, thread_states[THREAD->state]);
+			break;
+		}
+		THREAD = NULL;
+	}
+
+
+	THREAD = find_best_thread();
+	
+	spinlock_lock(&THREAD->lock);
+	priority = THREAD->priority;
+	spinlock_unlock(&THREAD->lock);	
+
+	relink_rq(priority);		
+
+	spinlock_lock(&THREAD->lock);	
+
+	/*
+	 * If both the old and the new task are the same, lots of work is avoided.
+	 */
+	if (TASK != THREAD->task) {
+		vm_t *m1 = NULL;
+		vm_t *m2;
+
+		if (TASK) {
+			spinlock_lock(&TASK->lock);
+			m1 = TASK->vm;
+			spinlock_unlock(&TASK->lock);
+		}
+
+		spinlock_lock(&THREAD->task->lock);
+		m2 = THREAD->task->vm;
+		spinlock_unlock(&THREAD->task->lock);
+		
+		/*
+		 * Note that it is possible for two tasks to share one vm mapping.
+		 */
+		if (m1 != m2) {
+			/*
+			 * Both tasks and vm mappings are different.
+			 * Replace the old one with the new one.
+			 */
+			vm_install(m2);
+		}
+		TASK = THREAD->task;	
+	}
+
+	THREAD->state = Running;
+
+	#ifdef SCHEDULER_VERBOSE
+	printf("cpu%d: tid %d (priority=%d,ticks=%d,nrdy=%d)\n", CPU->id, THREAD->tid, THREAD->priority, THREAD->ticks, CPU->nrdy);
+	#endif	
+
+	/*
+	 * Copy the knowledge of CPU, TASK, THREAD and preemption counter to thread's stack.
+	 */
+	the_copy(THE, (the_t *) THREAD->kstack);
+	
+	context_restore(&THREAD->saved_context);
+	/* not reached */
+}
+
+
 /** The scheduler
  *
@@ -320,142 +460,5 @@
 
 
-/** Scheduler stack switch wrapper
- *
- * Second part of the scheduler() function
- * using new stack. Handling the actual context
- * switch to a new thread.
- *
- */
-void scheduler_separated_stack(void)
-{
-	int priority;
-
-	ASSERT(CPU != NULL);
-
-	if (THREAD) {
-		switch (THREAD->state) {
-		    case Running:
-			THREAD->state = Ready;
-			spinlock_unlock(&THREAD->lock);
-			thread_ready(THREAD);
-			break;
-
-		    case Exiting:
-			frame_free((__address) THREAD->kstack);
-			if (THREAD->ustack) {
-				frame_free((__address) THREAD->ustack);
-			}
-
-			/*
-			 * Detach from the containing task.
-			 */
-			spinlock_lock(&TASK->lock);
-			list_remove(&THREAD->th_link);
-			spinlock_unlock(&TASK->lock);
-
-			spinlock_unlock(&THREAD->lock);
-    
-			spinlock_lock(&threads_lock);
-			list_remove(&THREAD->threads_link);
-			spinlock_unlock(&threads_lock);
-
-			spinlock_lock(&CPU->lock);
-			if(CPU->fpu_owner==THREAD) CPU->fpu_owner=NULL;
-			spinlock_unlock(&CPU->lock);
-
-			free(THREAD);
-
-			break;
-    
-		    case Sleeping:
-			/*
-			 * Prefer the thread after it's woken up.
-			 */
-			THREAD->priority = -1;
-
-			/*
-			 * We need to release wq->lock which we locked in waitq_sleep().
-			 * Address of wq->lock is kept in THREAD->sleep_queue.
-			 */
-			spinlock_unlock(&THREAD->sleep_queue->lock);
-
-			/*
-			 * Check for possible requests for out-of-context invocation.
-			 */
-			if (THREAD->call_me) {
-				THREAD->call_me(THREAD->call_me_with);
-				THREAD->call_me = NULL;
-				THREAD->call_me_with = NULL;
-			}
-
-			spinlock_unlock(&THREAD->lock);
-
-			break;
-
-		    default:
-			/*
-			 * Entering state is unexpected.
-			 */
-			panic("tid%d: unexpected state %s\n", THREAD->tid, thread_states[THREAD->state]);
-			break;
-		}
-		THREAD = NULL;
-	}
-
-
-	THREAD = find_best_thread();
-	
-	spinlock_lock(&THREAD->lock);
-	priority = THREAD->priority;
-	spinlock_unlock(&THREAD->lock);	
-
-	relink_rq(priority);		
-
-	spinlock_lock(&THREAD->lock);	
-
-	/*
-	 * If both the old and the new task are the same, lots of work is avoided.
-	 */
-	if (TASK != THREAD->task) {
-		vm_t *m1 = NULL;
-		vm_t *m2;
-
-		if (TASK) {
-			spinlock_lock(&TASK->lock);
-			m1 = TASK->vm;
-			spinlock_unlock(&TASK->lock);
-		}
-
-		spinlock_lock(&THREAD->task->lock);
-		m2 = THREAD->task->vm;
-		spinlock_unlock(&THREAD->task->lock);
-		
-		/*
-		 * Note that it is possible for two tasks to share one vm mapping.
-		 */
-		if (m1 != m2) {
-			/*
-			 * Both tasks and vm mappings are different.
-			 * Replace the old one with the new one.
-			 */
-			vm_install(m2);
-		}
-		TASK = THREAD->task;	
-	}
-
-	THREAD->state = Running;
-
-	#ifdef SCHEDULER_VERBOSE
-	printf("cpu%d: tid %d (priority=%d,ticks=%d,nrdy=%d)\n", CPU->id, THREAD->tid, THREAD->priority, THREAD->ticks, CPU->nrdy);
-	#endif	
-
-	/*
-	 * Copy the knowledge of CPU, TASK, THREAD and preemption counter to thread's stack.
-	 */
-	the_copy(THE, (the_t *) THREAD->kstack);
-	
-	context_restore(&THREAD->saved_context);
-	/* not reached */
-}
+
 
 
Index: generic/src/proc/thread.c
===================================================================
--- generic/src/proc/thread.c	(revision 169c408f8774661800aa0a9685c9914cbb5a974c)
+++ generic/src/proc/thread.c	(revision c4e8ed9d860723e9a528a63a1c23c93516a1e0ba)
@@ -71,5 +71,5 @@
  *
  */
-void cushion(void)
+static void cushion(void)
 {
 	void (*f)(void *) = THREAD->thread_code;
