patch-2.1.114 linux/kernel/exit.c

Next file: linux/kernel/fork.c
Previous file: linux/include/linux/smp_lock.h
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.113/linux/kernel/exit.c linux/kernel/exit.c
@@ -36,21 +36,31 @@
 {
 	if (p != current) {
 #ifdef __SMP__
-		/* FIXME! Cheesy, but kills the window... -DaveM */
-		do {
-			barrier();
-		} while (p->has_cpu);
-		spin_unlock_wait(&scheduler_lock);
+		/*
+		 * Wait to make sure the process isn't active on any
+		 * other CPU
+		 */
+		for (;;)  {
+			int has_cpu;
+			spin_lock(&scheduler_lock);
+			has_cpu = p->has_cpu;
+			spin_unlock(&scheduler_lock);
+			if (!has_cpu)
+				break;
+			do {
+				barrier();
+			} while (p->has_cpu);
+		}
 #endif
 		charge_uid(p, -1);
 		nr_tasks--;
 		add_free_taskslot(p->tarray_ptr);
-		{
-			write_lock_irq(&tasklist_lock);
-			unhash_pid(p);
-			REMOVE_LINKS(p);
-			write_unlock_irq(&tasklist_lock);
-		}
+
+		write_lock_irq(&tasklist_lock);
+		unhash_pid(p);
+		REMOVE_LINKS(p);
+		write_unlock_irq(&tasklist_lock);
+
 		release_thread(p);
 		current->cmin_flt += p->min_flt + p->cmin_flt;
 		current->cmaj_flt += p->maj_flt + p->cmaj_flt;
@@ -340,35 +350,39 @@
 
 NORET_TYPE void do_exit(long code)
 {
+	struct task_struct *tsk = current;
+
 	if (in_interrupt())
 		printk("Aiee, killing interrupt handler\n");
-	if (current == task[0])
+	if (!tsk->pid)
 		panic("Attempted to kill the idle task!");
+	tsk->flags |= PF_EXITING;
+	del_timer(&tsk->real_timer);
+
+	lock_kernel();
 fake_volatile:
-	current->flags |= PF_EXITING;
 #ifdef CONFIG_BSD_PROCESS_ACCT
 	acct_process(code);
 #endif
-	del_timer(&current->real_timer);
 	sem_exit();
-	__exit_mm(current);
+	__exit_mm(tsk);
 #if CONFIG_AP1000
-	exit_msc(current);
+	exit_msc(tsk);
 #endif
-	__exit_files(current);
-	__exit_fs(current);
-	__exit_sighand(current);
+	__exit_files(tsk);
+	__exit_fs(tsk);
+	__exit_sighand(tsk);
 	exit_thread();
-	current->state = TASK_ZOMBIE;
-	current->exit_code = code;
+	tsk->state = TASK_ZOMBIE;
+	tsk->exit_code = code;
 	exit_notify();
 #ifdef DEBUG_PROC_TREE
 	audit_ptree();
 #endif
-	if (current->exec_domain && current->exec_domain->module)
-		__MOD_DEC_USE_COUNT(current->exec_domain->module);
-	if (current->binfmt && current->binfmt->module)
-		__MOD_DEC_USE_COUNT(current->binfmt->module);
+	if (tsk->exec_domain && tsk->exec_domain->module)
+		__MOD_DEC_USE_COUNT(tsk->exec_domain->module);
+	if (tsk->binfmt && tsk->binfmt->module)
+		__MOD_DEC_USE_COUNT(tsk->binfmt->module);
 	schedule();
 /*
  * In order to get rid of the "volatile function does return" message
@@ -388,9 +402,7 @@
 
 asmlinkage int sys_exit(int error_code)
 {
-	lock_kernel();
 	do_exit((error_code&0xff)<<8);
-	unlock_kernel();
 }
 
 asmlinkage int sys_wait4(pid_t pid,unsigned int * stat_addr, int options, struct rusage * ru)

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov