summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_thread.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2011-03-24 18:40:11 +0000
committerjhb <jhb@FreeBSD.org>2011-03-24 18:40:11 +0000
commitc7ac62aecd199084355eed0c34e006b1a886e37e (patch)
treeb8f82913909a64d0acd11bf6bd0728bcb4cc6c84 /sys/kern/kern_thread.c
parent7a8bd43974c3b65965d0a1661898bf7a3f1ff052 (diff)
downloadFreeBSD-src-c7ac62aecd199084355eed0c34e006b1a886e37e.zip
FreeBSD-src-c7ac62aecd199084355eed0c34e006b1a886e37e.tar.gz
Fix some locking nits with the p_state field of struct proc:
- Hold the proc lock while changing the state from PRS_NEW to PRS_NORMAL in fork to honor the locking requirements. While here, expand the scope of the PROC_LOCK() on the new process (p2) to avoid some LORs. Previously the code was locking the new child process (p2) after it had locked the parent process (p1). However, when locking two processes, the safe order is to lock the child first, then the parent. - Fix various places that were checking p_state against PRS_NEW without having the process locked to use PROC_LOCK(). Every place was already locking the process, just after the PRS_NEW check. - Remove or reduce the use of PROC_SLOCK() for places that were checking p_state against PRS_NEW. The PROC_LOCK() alone is sufficient for reading the current state. - Reorder fill_kinfo_proc() slightly so it only acquires PROC_SLOCK() once. MFC after: 1 week
Diffstat (limited to 'sys/kern/kern_thread.c')
-rw-r--r--sys/kern/kern_thread.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c
index 5ef9864..29bdaa2 100644
--- a/sys/kern/kern_thread.c
+++ b/sys/kern/kern_thread.c
@@ -981,7 +981,9 @@ tdfind(lwpid_t tid, pid_t pid)
td = NULL;
break;
}
+ PROC_LOCK(td->td_proc);
if (td->td_proc->p_state == PRS_NEW) {
+ PROC_UNLOCK(td->td_proc);
td = NULL;
break;
}
@@ -990,12 +992,10 @@ tdfind(lwpid_t tid, pid_t pid)
LIST_REMOVE(td, td_hash);
LIST_INSERT_HEAD(TIDHASH(td->td_tid),
td, td_hash);
- PROC_LOCK(td->td_proc);
rw_wunlock(&tidhash_lock);
return (td);
}
}
- PROC_LOCK(td->td_proc);
break;
}
run++;
OpenPOWER on IntegriCloud