Accessing td_state requires thread lock to be held.

Submitted by:	Rudo Tomori
Reviewed by:	kib
This commit is contained in:
Edward Tomasz Napierala 2013-03-14 23:20:18 +00:00
parent 51ea07d722
commit 16befafd16

View File

@ -1033,6 +1033,7 @@ racct_proc_throttle(struct proc *p)
p->p_throttled = 1; p->p_throttled = 1;
FOREACH_THREAD_IN_PROC(p, td) { FOREACH_THREAD_IN_PROC(p, td) {
thread_lock(td);
switch (td->td_state) { switch (td->td_state) {
case TDS_RUNQ: case TDS_RUNQ:
/* /*
@ -1041,27 +1042,24 @@ racct_proc_throttle(struct proc *p)
* TDF_NEEDRESCHED for the thread, so that once it is * TDF_NEEDRESCHED for the thread, so that once it is
* running, it is taken off the cpu as soon as possible. * running, it is taken off the cpu as soon as possible.
*/ */
thread_lock(td);
td->td_flags |= TDF_NEEDRESCHED; td->td_flags |= TDF_NEEDRESCHED;
thread_unlock(td);
break; break;
case TDS_RUNNING: case TDS_RUNNING:
/* /*
* If the thread is running, we request a context * If the thread is running, we request a context
* switch for it by setting the TDF_NEEDRESCHED flag. * switch for it by setting the TDF_NEEDRESCHED flag.
*/ */
thread_lock(td);
td->td_flags |= TDF_NEEDRESCHED; td->td_flags |= TDF_NEEDRESCHED;
#ifdef SMP #ifdef SMP
cpuid = td->td_oncpu; cpuid = td->td_oncpu;
if ((cpuid != NOCPU) && (td != curthread)) if ((cpuid != NOCPU) && (td != curthread))
ipi_cpu(cpuid, IPI_AST); ipi_cpu(cpuid, IPI_AST);
#endif #endif
thread_unlock(td);
break; break;
default: default:
break; break;
} }
thread_unlock(td);
} }
} }