Index: src/proc/scheduler.c
===================================================================
--- src/proc/scheduler.c	(revision 397c77f3eabd20d194d7f9f89a7358eb5a0e23f8)
+++ src/proc/scheduler.c	(revision 7b7d7d1cbbddea9be6f0e75c0adabf7bda19ad53)
@@ -70,7 +70,7 @@
 	cpu_priority_high();
 
-	spinlock_lock(&the->cpu->lock);
-	n = the->cpu->nrdy;
-	spinlock_unlock(&the->cpu->lock);
+	spinlock_lock(&CPU->lock);
+	n = CPU->nrdy;
+	spinlock_unlock(&CPU->lock);
 
 	cpu_priority_low();
@@ -82,6 +82,6 @@
 		 * set CPU-private flag that the kcpulb has been started.
 		 */
-		if (test_and_set(&the->cpu->kcpulbstarted) == 0) {
-    			waitq_wakeup(&the->cpu->kcpulb_wq, 0);
+		if (test_and_set(&CPU->kcpulbstarted) == 0) {
+    			waitq_wakeup(&CPU->kcpulb_wq, 0);
 			goto loop;
 		}
@@ -101,5 +101,5 @@
 
 	for (i = 0; i<RQ_COUNT; i++) {
-		r = &the->cpu->rq[i];
+		r = &CPU->rq[i];
 		spinlock_lock(&r->lock);
 		if (r->n == 0) {
@@ -115,7 +115,7 @@
 		spinlock_unlock(&nrdylock);		
 
-		spinlock_lock(&the->cpu->lock);
-		the->cpu->nrdy--;
-		spinlock_unlock(&the->cpu->lock);
+		spinlock_lock(&CPU->lock);
+		CPU->nrdy--;
+		spinlock_unlock(&CPU->lock);
 
 		r->n--;
@@ -130,5 +130,5 @@
 
 		spinlock_lock(&t->lock);
-		t->cpu = the->cpu;
+		t->cpu = CPU;
 
 		t->ticks = us2ticks((i+1)*10000);
@@ -160,9 +160,9 @@
 
 	list_initialize(&head);
-	spinlock_lock(&the->cpu->lock);
-	if (the->cpu->needs_relink > NEEDS_RELINK_MAX) {
+	spinlock_lock(&CPU->lock);
+	if (CPU->needs_relink > NEEDS_RELINK_MAX) {
 		for (i = start; i<RQ_COUNT-1; i++) {
 			/* remember and empty rq[i + 1] */
-			r = &the->cpu->rq[i + 1];
+			r = &CPU->rq[i + 1];
 			spinlock_lock(&r->lock);
 			list_concat(&head, &r->rq_head);
@@ -172,5 +172,5 @@
 		
 			/* append rq[i + 1] to rq[i] */
-			r = &the->cpu->rq[i];
+			r = &CPU->rq[i];
 			spinlock_lock(&r->lock);
 			list_concat(&r->rq_head, &head);
@@ -178,7 +178,7 @@
 			spinlock_unlock(&r->lock);
 		}
-		the->cpu->needs_relink = 0;
-	}
-	spinlock_unlock(&the->cpu->lock);				
+		CPU->needs_relink = 0;
+	}
+	spinlock_unlock(&CPU->lock);				
 
 }
@@ -196,15 +196,15 @@
 		halt();
 
-	if (the->thread) {
-		spinlock_lock(&the->thread->lock);
-		if (!context_save(&the->thread->saved_context)) {
+	if (THREAD) {
+		spinlock_lock(&THREAD->lock);
+		if (!context_save(&THREAD->saved_context)) {
 			/*
 			 * This is the place where threads leave scheduler();
 			 */
-		    	spinlock_unlock(&the->thread->lock);
-			cpu_priority_restore(the->thread->saved_context.pri);
+		    	spinlock_unlock(&THREAD->lock);
+			cpu_priority_restore(THREAD->saved_context.pri);
 			return;
 		}
-		the->thread->saved_context.pri = pri;
+		THREAD->saved_context.pri = pri;
 	}
 
@@ -221,8 +221,8 @@
 	 * scheduler_separated_stack().
 	 */
-	context_save(&the->cpu->saved_context);
-	the->cpu->saved_context.sp = (__address) &the->cpu->stack[CPU_STACK_SIZE-8];
-	the->cpu->saved_context.pc = (__address) scheduler_separated_stack;
-	context_restore(&the->cpu->saved_context);
+	context_save(&CPU->saved_context);
+	CPU->saved_context.sp = (__address) &CPU->stack[CPU_STACK_SIZE-8];
+	CPU->saved_context.pc = (__address) scheduler_separated_stack;
+	context_restore(&CPU->saved_context);
 	/* not reached */
 }
@@ -232,16 +232,16 @@
 	int priority;
 
-	if (the->thread) {
-		switch (the->thread->state) {
+	if (THREAD) {
+		switch (THREAD->state) {
 		    case Running:
-			    the->thread->state = Ready;
-			    spinlock_unlock(&the->thread->lock);
-			    thread_ready(the->thread);
+			    THREAD->state = Ready;
+			    spinlock_unlock(&THREAD->lock);
+			    thread_ready(THREAD);
 			    break;
 
 		    case Exiting:
-			    frame_free((__address) the->thread->kstack);
-			    if (the->thread->ustack) {
-				    frame_free((__address) the->thread->ustack);
+			    frame_free((__address) THREAD->kstack);
+			    if (THREAD->ustack) {
+				    frame_free((__address) THREAD->ustack);
 			    }
 			    
@@ -249,15 +249,15 @@
 			     * Detach from the containing task.
 			     */
-			    spinlock_lock(&the->task->lock);
-			    list_remove(&the->thread->th_link);
-			    spinlock_unlock(&the->task->lock);
-
-			    spinlock_unlock(&the->thread->lock);
+			    spinlock_lock(&TASK->lock);
+			    list_remove(&THREAD->th_link);
+			    spinlock_unlock(&TASK->lock);
+
+			    spinlock_unlock(&THREAD->lock);
 			    
 			    spinlock_lock(&threads_lock);
-			    list_remove(&the->thread->threads_link);
+			    list_remove(&THREAD->threads_link);
 			    spinlock_unlock(&threads_lock);
 			    
-			    free(the->thread);
+			    free(THREAD);
 			    
 			    break;
@@ -267,22 +267,22 @@
 			     * Prefer the thread after it's woken up.
 			     */
-			    the->thread->pri = -1;
+			    THREAD->pri = -1;
 
 			    /*
 			     * We need to release wq->lock which we locked in waitq_sleep().
-			     * Address of wq->lock is kept in the->thread->sleep_queue.
+			     * Address of wq->lock is kept in THREAD->sleep_queue.
 			     */
-			    spinlock_unlock(&the->thread->sleep_queue->lock);
+			    spinlock_unlock(&THREAD->sleep_queue->lock);
 
 			    /*
 			     * Check for possible requests for out-of-context invocation.
 			     */
-			    if (the->thread->call_me) {
-				    the->thread->call_me(the->thread->call_me_with);
-				    the->thread->call_me = NULL;
-				    the->thread->call_me_with = NULL;
+			    if (THREAD->call_me) {
+				    THREAD->call_me(THREAD->call_me_with);
+				    THREAD->call_me = NULL;
+				    THREAD->call_me_with = NULL;
 			    }
 
-			    spinlock_unlock(&the->thread->lock);
+			    spinlock_unlock(&THREAD->lock);
 			    
 			    break;
@@ -292,36 +292,36 @@
 			     * Entering state is unexpected.
 			     */
-			    panic("tid%d: unexpected state %s\n", the->thread->tid, thread_states[the->thread->state]);
+			    panic("tid%d: unexpected state %s\n", THREAD->tid, thread_states[THREAD->state]);
 			    break;
 		}
-		the->thread = NULL;
+		THREAD = NULL;
 	}
     
-	the->thread = find_best_thread();
+	THREAD = find_best_thread();
 	
-	spinlock_lock(&the->thread->lock);
-	priority = the->thread->pri;
-	spinlock_unlock(&the->thread->lock);	
+	spinlock_lock(&THREAD->lock);
+	priority = THREAD->pri;
+	spinlock_unlock(&THREAD->lock);	
 	
 	relink_rq(priority);		
 
-	spinlock_lock(&the->thread->lock);	
+	spinlock_lock(&THREAD->lock);	
 
 	/*
 	 * If both the old and the new task are the same, lots of work is avoided.
 	 */
-	if (the->task != the->thread->task) {
+	if (TASK != THREAD->task) {
 		vm_t *m1 = NULL;
 		vm_t *m2;
 
-		if (the->task) {
-			spinlock_lock(&the->task->lock);
-			m1 = the->task->vm;
-			spinlock_unlock(&the->task->lock);
-		}
-
-		spinlock_lock(&the->thread->task->lock);
-		m2 = the->thread->task->vm;
-		spinlock_unlock(&the->thread->task->lock);
+		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);
 		
 		/*
@@ -338,14 +338,14 @@
 			vm_install(m2);
 		}
-		the->task = the->thread->task;	
-	}
-
-	the->thread->state = Running;
+		TASK = THREAD->task;	
+	}
+
+	THREAD->state = Running;
 
 	#ifdef SCHEDULER_VERBOSE
-	printf("cpu%d: tid %d (pri=%d,ticks=%d,nrdy=%d)\n", the->cpu->id, the->thread->tid, the->thread->pri, the->thread->ticks, the->cpu->nrdy);
+	printf("cpu%d: tid %d (pri=%d,ticks=%d,nrdy=%d)\n", CPU->id, THREAD->tid, THREAD->pri, THREAD->ticks, CPU->nrdy);
 	#endif	
 
-	context_restore(&the->thread->saved_context);
+	context_restore(&THREAD->saved_context);
 	/* not reached */
 }
@@ -366,5 +366,5 @@
 	 * Sleep until there's some work to do.
 	 */
-	waitq_sleep(&the->cpu->kcpulb_wq);
+	waitq_sleep(&CPU->kcpulb_wq);
 
 not_satisfied:
@@ -375,8 +375,8 @@
 	 */
 	pri = cpu_priority_high();
-	spinlock_lock(&the->cpu->lock);
+	spinlock_lock(&CPU->lock);
 	count = nrdy / config.cpu_active;
-	count -= the->cpu->nrdy;
-	spinlock_unlock(&the->cpu->lock);
+	count -= CPU->nrdy;
+	spinlock_unlock(&CPU->lock);
 	cpu_priority_restore(pri);
 
@@ -400,5 +400,5 @@
 			 * Doesn't require interrupt disabling for kcpulb is X_WIRED.
 			 */
-			if (the->cpu == cpu)
+			if (CPU == cpu)
 				continue;
 
@@ -461,5 +461,5 @@
 				spinlock_lock(&t->lock);
 				#ifdef KCPULB_VERBOSE
-				printf("kcpulb%d: TID %d -> cpu%d, nrdy=%d, avg=%d\n", the->cpu->id, t->tid, the->cpu->id, the->cpu->nrdy, nrdy / config.cpu_active);
+				printf("kcpulb%d: TID %d -> cpu%d, nrdy=%d, avg=%d\n", CPU->id, t->tid, CPU->id, CPU->nrdy, nrdy / config.cpu_active);
 				#endif
 				t->flags |= X_STOLEN;
@@ -484,5 +484,5 @@
 	}
 
-	if (the->cpu->nrdy) {
+	if (CPU->nrdy) {
 		/*
 		 * Be a little bit light-weight and let migrated threads run.
@@ -504,5 +504,5 @@
 	 * Tell find_best_thread() to wake us up later again.
 	 */
-	the->cpu->kcpulbstarted = 0;
+	CPU->kcpulbstarted = 0;
 	goto loop;
 }
