- /*
- * If priority was low (>PZERO) and
- * there has been a signal, execute non-local goto through
- * u.u_qsave, aborting the system call in progress (see trap.c)
- */
-psig:
- longjmp(&u.u_qsave);
- /*NOTREACHED*/
+/*
+ * Short-term, non-interruptable sleep.
+ */
+sleep(chan, pri)
+ caddr_t chan;
+ int pri;
+{
+ register struct proc *rp;
+ register struct slpque *qp;
+ register s;
+ extern int cold;
+
+#ifdef DIAGNOSTIC
+ if (pri > PZERO) {
+ printf("sleep called with pri %d > PZERO, wchan: %x\n",
+ pri, chan);
+ panic("old sleep");
+ }
+#endif
+ rp = u.u_procp;
+ s = splhigh();
+ if (cold || panicstr) {
+ /*
+ * After a panic, or during autoconfiguration,
+ * just give interrupts a chance, then just return;
+ * don't run any other procs or panic below,
+ * in case this is the idle process and already asleep.
+ */
+ (void) spl0();
+ splx(s);
+ return;
+ }
+#ifdef DIAGNOSTIC
+ if (chan==0 || rp->p_stat != SRUN || rp->p_rlink)
+ panic("sleep");
+#endif
+ rp->p_wchan = chan;
+ rp->p_wmesg = NULL;
+ rp->p_slptime = 0;
+ rp->p_pri = pri;
+ qp = &slpque[HASH(chan)];
+ if (qp->sq_head == 0)
+ qp->sq_head = rp;
+ else
+ *qp->sq_tailp = rp;
+ *(qp->sq_tailp = &rp->p_link) = 0;
+ rp->p_stat = SSLEEP;
+ (void) spl0();
+ u.u_ru.ru_nvcsw++;
+ swtch();
+ curpri = rp->p_usrpri;
+ splx(s);