From e631cff309016b9320ff638f2c3a193942dd6eda Mon Sep 17 00:00:00 2001 From: David Xu Date: Mon, 10 Apr 2006 04:55:59 +0000 Subject: [PATCH] Use proc lock to prevent a thread from exiting, Giant was no longer used to protect thread list. --- sys/kern/ksched.c | 2 +- sys/kern/p1003_1b.c | 35 +++++++++-------------------------- sys/posix4/ksched.c | 2 +- sys/posix4/p1003_1b.c | 35 +++++++++-------------------------- 4 files changed, 20 insertions(+), 54 deletions(-) diff --git a/sys/kern/ksched.c b/sys/kern/ksched.c index a266c575df52..701d86a4e84c 100644 --- a/sys/kern/ksched.c +++ b/sys/kern/ksched.c @@ -177,7 +177,7 @@ int ksched_setscheduler(register_t *ret, struct ksched *ksched, case SCHED_FIFO: if (param->sched_priority >= P1B_PRIO_MIN && - param->sched_priority <= P1B_PRIO_MAX) + param->sched_priority <= P1B_PRIO_MAX) { rtp.prio = p4prio_to_rtpprio(param->sched_priority); rtp.type = (policy == SCHED_FIFO) diff --git a/sys/kern/p1003_1b.c b/sys/kern/p1003_1b.c index 7f366f1483cc..f40f0c99f64f 100644 --- a/sys/kern/p1003_1b.c +++ b/sys/kern/p1003_1b.c @@ -121,7 +121,6 @@ int sched_setparam(struct thread *td, if (e) return (e); - mtx_lock(&Giant); if (uap->pid == 0) { targetp = td->td_proc; targettd = td; @@ -136,13 +135,12 @@ int sched_setparam(struct thread *td, } e = p_cansched(td, targetp); - PROC_UNLOCK(targetp); if (e == 0) { e = ksched_setparam(&td->td_retval[0], ksched, targettd, (const struct sched_param *)&sched_param); } + PROC_UNLOCK(targetp); done2: - mtx_unlock(&Giant); return (e); } @@ -157,7 +155,6 @@ int sched_getparam(struct thread *td, struct thread *targettd; struct proc *targetp; - mtx_lock(&Giant); if (uap->pid == 0) { targetp = td->td_proc; targettd = td; @@ -172,15 +169,14 @@ int sched_getparam(struct thread *td, } e = p_cansee(td, targetp); + if (e == 0) { + e = ksched_getparam(&td->td_retval[0], ksched, targettd, + &sched_param); + } PROC_UNLOCK(targetp); - if (e) - goto done2; - - e = ksched_getparam(&td->td_retval[0], ksched, targettd, &sched_param); if (e == 0) e = copyout(&sched_param, uap->param, sizeof(sched_param)); done2: - mtx_unlock(&Giant); return (e); } @@ -199,7 +195,6 @@ int sched_setscheduler(struct thread *td, if (e) return (e); - mtx_lock(&Giant); if (uap->pid == 0) { targetp = td->td_proc; targettd = td; @@ -214,13 +209,12 @@ int sched_setscheduler(struct thread *td, } e = p_cansched(td, targetp); - PROC_UNLOCK(targetp); if (e == 0) { e = ksched_setscheduler(&td->td_retval[0], ksched, targettd, uap->policy, (const struct sched_param *)&sched_param); } + PROC_UNLOCK(targetp); done2: - mtx_unlock(&Giant); return (e); } @@ -234,7 +228,6 @@ int sched_getscheduler(struct thread *td, struct thread *targettd; struct proc *targetp; - mtx_lock(&Giant); if (uap->pid == 0) { targetp = td->td_proc; targettd = td; @@ -249,12 +242,11 @@ int sched_getscheduler(struct thread *td, } e = p_cansee(td, targetp); - PROC_UNLOCK(targetp); if (e == 0) e = ksched_getscheduler(&td->td_retval[0], ksched, targettd); + PROC_UNLOCK(targetp); done2: - mtx_unlock(&Giant); return (e); } @@ -266,9 +258,7 @@ int sched_yield(struct thread *td, { int error; - mtx_lock(&Giant); error = ksched_yield(&td->td_retval[0], ksched); - mtx_unlock(&Giant); return (error); } @@ -280,9 +270,7 @@ int sched_get_priority_max(struct thread *td, { int error; - mtx_lock(&Giant); error = ksched_get_priority_max(&td->td_retval[0], ksched, uap->policy); - mtx_unlock(&Giant); return (error); } @@ -294,9 +282,7 @@ int sched_get_priority_min(struct thread *td, { int error; - mtx_lock(&Giant); error = ksched_get_priority_min(&td->td_retval[0], ksched, uap->policy); - mtx_unlock(&Giant); return (error); } @@ -322,17 +308,15 @@ int kern_sched_rr_get_interval(struct thread *td, pid_t pid, struct thread *targettd; struct proc *targetp; - mtx_lock(&Giant); if (pid == 0) { targettd = td; targetp = td->td_proc; PROC_LOCK(targetp); } else { targetp = pfind(pid); - if (targetp == NULL) { - mtx_unlock(&Giant); + if (targetp == NULL) return (ESRCH); - } + targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */ } @@ -341,7 +325,6 @@ int kern_sched_rr_get_interval(struct thread *td, pid_t pid, e = ksched_rr_get_interval(&td->td_retval[0], ksched, targettd, ts); PROC_UNLOCK(targetp); - mtx_unlock(&Giant); return (e); } diff --git a/sys/posix4/ksched.c b/sys/posix4/ksched.c index a266c575df52..701d86a4e84c 100644 --- a/sys/posix4/ksched.c +++ b/sys/posix4/ksched.c @@ -177,7 +177,7 @@ int ksched_setscheduler(register_t *ret, struct ksched *ksched, case SCHED_FIFO: if (param->sched_priority >= P1B_PRIO_MIN && - param->sched_priority <= P1B_PRIO_MAX) + param->sched_priority <= P1B_PRIO_MAX) { rtp.prio = p4prio_to_rtpprio(param->sched_priority); rtp.type = (policy == SCHED_FIFO) diff --git a/sys/posix4/p1003_1b.c b/sys/posix4/p1003_1b.c index 7f366f1483cc..f40f0c99f64f 100644 --- a/sys/posix4/p1003_1b.c +++ b/sys/posix4/p1003_1b.c @@ -121,7 +121,6 @@ int sched_setparam(struct thread *td, if (e) return (e); - mtx_lock(&Giant); if (uap->pid == 0) { targetp = td->td_proc; targettd = td; @@ -136,13 +135,12 @@ int sched_setparam(struct thread *td, } e = p_cansched(td, targetp); - PROC_UNLOCK(targetp); if (e == 0) { e = ksched_setparam(&td->td_retval[0], ksched, targettd, (const struct sched_param *)&sched_param); } + PROC_UNLOCK(targetp); done2: - mtx_unlock(&Giant); return (e); } @@ -157,7 +155,6 @@ int sched_getparam(struct thread *td, struct thread *targettd; struct proc *targetp; - mtx_lock(&Giant); if (uap->pid == 0) { targetp = td->td_proc; targettd = td; @@ -172,15 +169,14 @@ int sched_getparam(struct thread *td, } e = p_cansee(td, targetp); + if (e == 0) { + e = ksched_getparam(&td->td_retval[0], ksched, targettd, + &sched_param); + } PROC_UNLOCK(targetp); - if (e) - goto done2; - - e = ksched_getparam(&td->td_retval[0], ksched, targettd, &sched_param); if (e == 0) e = copyout(&sched_param, uap->param, sizeof(sched_param)); done2: - mtx_unlock(&Giant); return (e); } @@ -199,7 +195,6 @@ int sched_setscheduler(struct thread *td, if (e) return (e); - mtx_lock(&Giant); if (uap->pid == 0) { targetp = td->td_proc; targettd = td; @@ -214,13 +209,12 @@ int sched_setscheduler(struct thread *td, } e = p_cansched(td, targetp); - PROC_UNLOCK(targetp); if (e == 0) { e = ksched_setscheduler(&td->td_retval[0], ksched, targettd, uap->policy, (const struct sched_param *)&sched_param); } + PROC_UNLOCK(targetp); done2: - mtx_unlock(&Giant); return (e); } @@ -234,7 +228,6 @@ int sched_getscheduler(struct thread *td, struct thread *targettd; struct proc *targetp; - mtx_lock(&Giant); if (uap->pid == 0) { targetp = td->td_proc; targettd = td; @@ -249,12 +242,11 @@ int sched_getscheduler(struct thread *td, } e = p_cansee(td, targetp); - PROC_UNLOCK(targetp); if (e == 0) e = ksched_getscheduler(&td->td_retval[0], ksched, targettd); + PROC_UNLOCK(targetp); done2: - mtx_unlock(&Giant); return (e); } @@ -266,9 +258,7 @@ int sched_yield(struct thread *td, { int error; - mtx_lock(&Giant); error = ksched_yield(&td->td_retval[0], ksched); - mtx_unlock(&Giant); return (error); } @@ -280,9 +270,7 @@ int sched_get_priority_max(struct thread *td, { int error; - mtx_lock(&Giant); error = ksched_get_priority_max(&td->td_retval[0], ksched, uap->policy); - mtx_unlock(&Giant); return (error); } @@ -294,9 +282,7 @@ int sched_get_priority_min(struct thread *td, { int error; - mtx_lock(&Giant); error = ksched_get_priority_min(&td->td_retval[0], ksched, uap->policy); - mtx_unlock(&Giant); return (error); } @@ -322,17 +308,15 @@ int kern_sched_rr_get_interval(struct thread *td, pid_t pid, struct thread *targettd; struct proc *targetp; - mtx_lock(&Giant); if (pid == 0) { targettd = td; targetp = td->td_proc; PROC_LOCK(targetp); } else { targetp = pfind(pid); - if (targetp == NULL) { - mtx_unlock(&Giant); + if (targetp == NULL) return (ESRCH); - } + targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */ } @@ -341,7 +325,6 @@ int kern_sched_rr_get_interval(struct thread *td, pid_t pid, e = ksched_rr_get_interval(&td->td_retval[0], ksched, targettd, ts); PROC_UNLOCK(targetp); - mtx_unlock(&Giant); return (e); }