Print this page
OS-7753 THREAD_KPRI_RELEASE does nothing of the sort
Reviewed by: Bryan Cantrill <bryan@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>


 686                 return (NULL);
 687         mutex_enter(&p->p_lock);
 688         while (p->p_proc_flag & P_PR_LOCK) {
 689                 /*
 690                  * This cv/mutex pair is persistent even if
 691                  * the process disappears while we sleep.
 692                  */
 693                 kcondvar_t *cv = &pr_pid_cv[p->p_slot];
 694                 kmutex_t *mp = &p->p_lock;
 695 
 696                 mutex_exit(&pr_pidlock);
 697                 cv_wait(cv, mp);
 698                 mutex_exit(mp);
 699                 mutex_enter(&pr_pidlock);
 700                 if (pcp->prc_proc == NULL)
 701                         return (NULL);
 702                 ASSERT(p == pcp->prc_proc);
 703                 mutex_enter(&p->p_lock);
 704         }
 705         p->p_proc_flag |= P_PR_LOCK;
 706         THREAD_KPRI_REQUEST();
 707         return (p);
 708 }
 709 
 710 /*
 711  * Lock the target process by setting P_PR_LOCK and grabbing p->p_lock.
 712  * This prevents any lwp of the process from disappearing and
 713  * blocks most operations that a process can perform on itself.
 714  * Returns 0 on success, a non-zero error number on failure.
 715  *
 716  * 'zdisp' is ZYES or ZNO to indicate whether prlock() should succeed when
 717  * the subject process is a zombie (ZYES) or fail for zombies (ZNO).
 718  *
 719  * error returns:
 720  *      ENOENT: process or lwp has disappeared or process is exiting
 721  *              (or has become a zombie and zdisp == ZNO).
 722  *      EAGAIN: procfs vnode has become invalid.
 723  *      EINTR:  signal arrived while waiting for exec to complete.
 724  */
 725 int
 726 prlock(prnode_t *pnp, int zdisp)


 793         return (0);
 794 }
 795 
 796 /*
 797  * Undo prlock() and pr_p_lock().
 798  * p->p_lock is still held; pr_pidlock is no longer held.
 799  *
 800  * prunmark() drops the P_PR_LOCK flag and wakes up another thread,
 801  * if any, waiting for the flag to be dropped; it retains p->p_lock.
 802  *
 803  * prunlock() calls prunmark() and then drops p->p_lock.
 804  */
 805 void
 806 prunmark(proc_t *p)
 807 {
 808         ASSERT(p->p_proc_flag & P_PR_LOCK);
 809         ASSERT(MUTEX_HELD(&p->p_lock));
 810 
 811         cv_signal(&pr_pid_cv[p->p_slot]);
 812         p->p_proc_flag &= ~P_PR_LOCK;
 813         THREAD_KPRI_RELEASE();
 814 }
 815 
 816 void
 817 prunlock(prnode_t *pnp)
 818 {
 819         prcommon_t *pcp = pnp->pr_common;
 820         proc_t *p = pcp->prc_proc;
 821 
 822         /*
 823          * If we (or someone) gave it a SIGKILL, and it is not
 824          * already a zombie, set it running unconditionally.
 825          */
 826         if ((p->p_flag & SKILLED) &&
 827             !(p->p_flag & SEXITING) &&
 828             !(pcp->prc_flags & PRC_DESTROY) &&
 829             !((pcp->prc_flags & PRC_LWP) && pcp->prc_tslot == -1))
 830                 (void) pr_setrun(pnp, 0);
 831         prunmark(p);
 832         mutex_exit(&p->p_lock);
 833 }




 686                 return (NULL);
 687         mutex_enter(&p->p_lock);
 688         while (p->p_proc_flag & P_PR_LOCK) {
 689                 /*
 690                  * This cv/mutex pair is persistent even if
 691                  * the process disappears while we sleep.
 692                  */
 693                 kcondvar_t *cv = &pr_pid_cv[p->p_slot];
 694                 kmutex_t *mp = &p->p_lock;
 695 
 696                 mutex_exit(&pr_pidlock);
 697                 cv_wait(cv, mp);
 698                 mutex_exit(mp);
 699                 mutex_enter(&pr_pidlock);
 700                 if (pcp->prc_proc == NULL)
 701                         return (NULL);
 702                 ASSERT(p == pcp->prc_proc);
 703                 mutex_enter(&p->p_lock);
 704         }
 705         p->p_proc_flag |= P_PR_LOCK;

 706         return (p);
 707 }
 708 
 709 /*
 710  * Lock the target process by setting P_PR_LOCK and grabbing p->p_lock.
 711  * This prevents any lwp of the process from disappearing and
 712  * blocks most operations that a process can perform on itself.
 713  * Returns 0 on success, a non-zero error number on failure.
 714  *
 715  * 'zdisp' is ZYES or ZNO to indicate whether prlock() should succeed when
 716  * the subject process is a zombie (ZYES) or fail for zombies (ZNO).
 717  *
 718  * error returns:
 719  *      ENOENT: process or lwp has disappeared or process is exiting
 720  *              (or has become a zombie and zdisp == ZNO).
 721  *      EAGAIN: procfs vnode has become invalid.
 722  *      EINTR:  signal arrived while waiting for exec to complete.
 723  */
 724 int
 725 prlock(prnode_t *pnp, int zdisp)


 792         return (0);
 793 }
 794 
 795 /*
 796  * Undo prlock() and pr_p_lock().
 797  * p->p_lock is still held; pr_pidlock is no longer held.
 798  *
 799  * prunmark() drops the P_PR_LOCK flag and wakes up another thread,
 800  * if any, waiting for the flag to be dropped; it retains p->p_lock.
 801  *
 802  * prunlock() calls prunmark() and then drops p->p_lock.
 803  */
 804 void
 805 prunmark(proc_t *p)
 806 {
 807         ASSERT(p->p_proc_flag & P_PR_LOCK);
 808         ASSERT(MUTEX_HELD(&p->p_lock));
 809 
 810         cv_signal(&pr_pid_cv[p->p_slot]);
 811         p->p_proc_flag &= ~P_PR_LOCK;

 812 }
 813 
 814 void
 815 prunlock(prnode_t *pnp)
 816 {
 817         prcommon_t *pcp = pnp->pr_common;
 818         proc_t *p = pcp->prc_proc;
 819 
 820         /*
 821          * If we (or someone) gave it a SIGKILL, and it is not
 822          * already a zombie, set it running unconditionally.
 823          */
 824         if ((p->p_flag & SKILLED) &&
 825             !(p->p_flag & SEXITING) &&
 826             !(pcp->prc_flags & PRC_DESTROY) &&
 827             !((pcp->prc_flags & PRC_LWP) && pcp->prc_tslot == -1))
 828                 (void) pr_setrun(pnp, 0);
 829         prunmark(p);
 830         mutex_exit(&p->p_lock);
 831 }