-/* $OpenBSD: dt_dev.c,v 1.26 2023/04/26 16:53:59 claudio Exp $ */
+/* $OpenBSD: dt_dev.c,v 1.27 2023/06/28 08:23:25 claudio Exp $ */
/*
* Copyright (c) 2019 Martin Pieuchot <mpi@openbsd.org>
return (EMSGSIZE);
while (!sc->ds_evtcnt) {
- sleep_setup(&sls, sc, PWAIT | PCATCH, "dtread", 0);
- error = sleep_finish(&sls, !sc->ds_evtcnt);
+ sleep_setup(&sls, sc, PWAIT | PCATCH, "dtread");
+ error = sleep_finish(&sls, PWAIT | PCATCH, 0, !sc->ds_evtcnt);
if (error == EINTR || error == ERESTART)
break;
}
-/* $OpenBSD: drm_linux.c,v 1.98 2023/06/01 10:21:26 claudio Exp $ */
+/* $OpenBSD: drm_linux.c,v 1.99 2023/06/28 08:23:25 claudio Exp $ */
/*
* Copyright (c) 2013 Jonathan Gray <jsg@openbsd.org>
* Copyright (c) 2015, 2016 Mark Kettenis <kettenis@openbsd.org>
{
struct sleep_state sls;
unsigned long deadline;
- int wait, spl, timo = 0;
+ int wait, spl, prio, timo = 0;
MUTEX_ASSERT_LOCKED(&sch_mtx);
KASSERT(!cold);
if (timeout != MAX_SCHEDULE_TIMEOUT)
timo = timeout;
- sleep_setup(&sls, sch_ident, sch_priority, "schto", timo);
+ prio = sch_priority;
+ sleep_setup(&sls, sch_ident, prio, "schto");
wait = (sch_proc == curproc && timeout > 0);
if (timeout != MAX_SCHEDULE_TIMEOUT)
deadline = jiffies + timeout;
- sleep_finish(&sls, wait);
+ sleep_finish(&sls, prio, timo, wait);
if (timeout != MAX_SCHEDULE_TIMEOUT)
timeout = deadline - jiffies;
-/* $OpenBSD: if_myx.c,v 1.116 2022/03/11 18:00:48 mpi Exp $ */
+/* $OpenBSD: if_myx.c,v 1.117 2023/06/28 08:23:25 claudio Exp $ */
/*
* Copyright (c) 2007 Reyk Floeter <reyk@openbsd.org>
(void)myx_cmd(sc, MYXCMD_SET_IFDOWN, &mc, NULL);
while (sc->sc_state != MYX_S_OFF) {
- sleep_setup(&sls, sts, PWAIT, "myxdown", 0);
+ sleep_setup(&sls, sts, PWAIT, "myxdown");
membar_consumer();
- sleep_finish(&sls, sc->sc_state != MYX_S_OFF);
+ sleep_finish(&sls, PWAIT, 0, sc->sc_state != MYX_S_OFF);
}
s = splnet();
-/* $OpenBSD: kern_rwlock.c,v 1.48 2022/05/10 16:56:16 bluhm Exp $ */
+/* $OpenBSD: kern_rwlock.c,v 1.49 2023/06/28 08:23:25 claudio Exp $ */
/*
* Copyright (c) 2002, 2003 Artur Grabowski <art@openbsd.org>
prio = op->wait_prio;
if (flags & RW_INTR)
prio |= PCATCH;
- sleep_setup(&sls, rwl, prio, rwl->rwl_name, 0);
+ sleep_setup(&sls, rwl, prio, rwl->rwl_name);
do_sleep = !rw_cas(&rwl->rwl_owner, o, set);
- error = sleep_finish(&sls, do_sleep);
+ error = sleep_finish(&sls, prio, 0, do_sleep);
if ((flags & RW_INTR) &&
(error != 0))
return (error);
-/* $OpenBSD: kern_sched.c,v 1.76 2022/12/05 23:18:37 deraadt Exp $ */
+/* $OpenBSD: kern_sched.c,v 1.77 2023/06/28 08:23:25 claudio Exp $ */
/*
* Copyright (c) 2007, 2008 Artur Grabowski <art@openbsd.org>
*
if (CPU_IS_PRIMARY(ci) || !CPU_IS_RUNNING(ci))
continue;
while ((spc->spc_schedflags & SPCF_HALTED) == 0) {
- sleep_setup(&sls, spc, PZERO, "schedstate", 0);
- sleep_finish(&sls,
+ sleep_setup(&sls, spc, PZERO, "schedstate");
+ sleep_finish(&sls, PZERO, 0,
(spc->spc_schedflags & SPCF_HALTED) == 0);
}
}
-/* $OpenBSD: kern_sig.c,v 1.306 2023/04/03 11:57:50 claudio Exp $ */
+/* $OpenBSD: kern_sig.c,v 1.307 2023/06/28 08:23:25 claudio Exp $ */
/* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */
/*
/* wait until they're all suspended */
wait = pr->ps_singlecount > 0;
while (wait) {
- sleep_setup(&sls, &pr->ps_singlecount, PWAIT, "suspend", 0);
+ sleep_setup(&sls, &pr->ps_singlecount, PWAIT, "suspend");
wait = pr->ps_singlecount > 0;
- sleep_finish(&sls, wait);
+ sleep_finish(&sls, PWAIT, 0, wait);
if (!recheck)
break;
}
-/* $OpenBSD: kern_synch.c,v 1.192 2023/06/01 10:21:26 claudio Exp $ */
+/* $OpenBSD: kern_synch.c,v 1.193 2023/06/28 08:23:25 claudio Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*
return (0);
}
- sleep_setup(&sls, ident, priority, wmesg, timo);
- return sleep_finish(&sls, 1);
+ sleep_setup(&sls, ident, priority, wmesg);
+ return sleep_finish(&sls, priority, timo, 1);
}
int
return (0);
}
- sleep_setup(&sls, ident, priority, wmesg, timo);
+ sleep_setup(&sls, ident, priority, wmesg);
/* XXX - We need to make sure that the mutex doesn't
* unblock splsched. This can be made a bit more
MUTEX_OLDIPL(mtx) = splsched();
mtx_leave(mtx);
/* signal may stop the process, release mutex before that */
- error = sleep_finish(&sls, 1);
+ error = sleep_finish(&sls, priority, timo, 1);
if ((priority & PNORELOCK) == 0) {
mtx_enter(mtx);
rw_assert_anylock(rwl);
status = rw_status(rwl);
- sleep_setup(&sls, ident, priority, wmesg, timo);
+ sleep_setup(&sls, ident, priority, wmesg);
rw_exit(rwl);
/* signal may stop the process, release rwlock before that */
- error = sleep_finish(&sls, 1);
+ error = sleep_finish(&sls, priority, timo, 1);
if ((priority & PNORELOCK) == 0)
rw_enter(rwl, status);
void
sleep_setup(struct sleep_state *sls, const volatile void *ident, int prio,
- const char *wmesg, int timo)
+ const char *wmesg)
{
struct proc *p = curproc;
panic("tsleep: not SONPROC");
#endif
- sls->sls_catch = prio & PCATCH;
- sls->sls_timeout = 0;
-
SCHED_LOCK(sls->sls_s);
TRACEPOINT(sched, sleep, NULL);
p->p_slppri = prio & PRIMASK;
TAILQ_INSERT_TAIL(&slpque[LOOKUP(ident)], p, p_runq);
- if (timo) {
- KASSERT((p->p_flag & P_TIMEOUT) == 0);
- sls->sls_timeout = 1;
- timeout_add(&p->p_sleep_to, timo);
- }
}
int
-sleep_finish(struct sleep_state *sls, int do_sleep)
+sleep_finish(struct sleep_state *sls, int prio, int timo, int do_sleep)
{
struct proc *p = curproc;
- int error = 0, error1 = 0;
+ int catch, error = 0, error1 = 0;
+
+ catch = prio & PCATCH;
+
+ if (timo != 0) {
+ KASSERT((p->p_flag & P_TIMEOUT) == 0);
+ timeout_add(&p->p_sleep_to, timo);
+ }
- if (sls->sls_catch != 0) {
+ if (catch != 0) {
/*
* We put ourselves on the sleep queue and start our
* timeout before calling sleep_signal_check(), as we could
atomic_setbits_int(&p->p_flag, P_SINTR);
if ((error = sleep_signal_check()) != 0) {
p->p_stat = SONPROC;
- sls->sls_catch = 0;
+ catch = 0;
do_sleep = 0;
} else if (p->p_wchan == NULL) {
- sls->sls_catch = 0;
+ catch = 0;
do_sleep = 0;
}
}
*/
atomic_clearbits_int(&p->p_flag, P_SINTR);
- if (sls->sls_timeout) {
+ if (timo != 0) {
if (p->p_flag & P_TIMEOUT) {
error1 = EWOULDBLOCK;
} else {
}
/* Check if thread was woken up because of a unwind or signal */
- if (sls->sls_catch != 0)
+ if (catch != 0)
error = sleep_signal_check();
/* Signal errors are higher priority than timeouts. */
KASSERT(refs != ~0);
TRACEINDEX(refcnt, r->r_traceidx, r, refs + 1, -1);
while (refs) {
- sleep_setup(&sls, r, PWAIT, wmesg, 0);
+ sleep_setup(&sls, r, PWAIT, wmesg);
refs = atomic_load_int(&r->r_refs);
- sleep_finish(&sls, refs);
+ sleep_finish(&sls, PWAIT, 0, refs);
}
TRACEINDEX(refcnt, r->r_traceidx, r, refs, 0);
/* Order subsequent loads and stores after refs == 0 load. */
wait = atomic_load_int(&c->c_wait);
while (wait) {
- sleep_setup(&sls, c, PWAIT, wmesg, 0);
+ sleep_setup(&sls, c, PWAIT, wmesg);
wait = atomic_load_int(&c->c_wait);
- sleep_finish(&sls, wait);
+ sleep_finish(&sls, PWAIT, 0, wait);
}
}
-/* $OpenBSD: kern_timeout.c,v 1.91 2023/06/26 16:26:20 cheloha Exp $ */
+/* $OpenBSD: kern_timeout.c,v 1.92 2023/06/28 08:23:25 claudio Exp $ */
/*
* Copyright (c) 2001 Thomas Nordin <nordin@openbsd.org>
* Copyright (c) 2000-2001 Artur Grabowski <art@openbsd.org>
s = splsoftclock();
for (;;) {
- sleep_setup(&sls, &timeout_proc, PSWP, "bored", 0);
- sleep_finish(&sls, CIRCQ_EMPTY(&timeout_proc));
+ sleep_setup(&sls, &timeout_proc, PSWP, "bored");
+ sleep_finish(&sls, PSWP, 0, CIRCQ_EMPTY(&timeout_proc));
mtx_enter(&timeout_mutex);
while (!CIRCQ_EMPTY(&timeout_proc)) {
-/* $OpenBSD: subr_log.c,v 1.75 2022/07/02 08:50:42 visa Exp $ */
+/* $OpenBSD: subr_log.c,v 1.76 2023/06/28 08:23:25 claudio Exp $ */
/* $NetBSD: subr_log.c,v 1.11 1996/03/30 22:24:44 christos Exp $ */
/*
* Set up and enter sleep manually instead of using msleep()
* to keep log_mtx as a leaf lock.
*/
- sleep_setup(&sls, mbp, LOG_RDPRI | PCATCH, "klog", 0);
- error = sleep_finish(&sls, logsoftc.sc_state & LOG_RDWAIT);
+ sleep_setup(&sls, mbp, LOG_RDPRI | PCATCH, "klog");
+ error = sleep_finish(&sls, LOG_RDPRI | PCATCH, 0,
+ logsoftc.sc_state & LOG_RDWAIT);
mtx_enter(&log_mtx);
if (error)
goto out;
-/* $OpenBSD: proc.h,v 1.341 2023/06/01 10:21:26 claudio Exp $ */
+/* $OpenBSD: proc.h,v 1.342 2023/06/28 08:23:25 claudio Exp $ */
/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
/*-
struct sleep_state {
int sls_s;
- int sls_catch;
- int sls_timeout;
};
struct cond {
-/* $OpenBSD: systm.h,v 1.161 2023/01/31 15:18:56 deraadt Exp $ */
+/* $OpenBSD: systm.h,v 1.162 2023/06/28 08:23:25 claudio Exp $ */
/* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */
/*-
struct sleep_state;
void sleep_setup(struct sleep_state *, const volatile void *, int,
- const char *, int);
-int sleep_finish(struct sleep_state *, int);
+ const char *);
+int sleep_finish(struct sleep_state *, int, int, int);
void sleep_queue_init(void);
struct cond;