Index: share/man/man9/tsleep.9 =================================================================== RCS file: /cvs/src/share/man/man9/tsleep.9,v diff -u -p -r1.16 tsleep.9 --- share/man/man9/tsleep.9 31 Mar 2022 17:27:23 -0000 1.16 +++ share/man/man9/tsleep.9 17 Oct 2024 23:06:37 -0000 @@ -93,11 +93,11 @@ .Fa "const char *wmesg" .Fa "uint64_t nsecs" .Fc -.Ft void +.Ft int .Fn wakeup "void *ident" -.Ft void +.Ft int .Fn wakeup_n "void *ident" "int count" -.Ft void +.Ft int .Fn wakeup_one "void *ident" .Sh DESCRIPTION These functions implement voluntary context switching. @@ -278,6 +278,12 @@ and otherwise. If they return as a result of a timeout, the return value is .Er EWOULDBLOCK . +.Pp +.Fn wakeup , +.Fn wakeup n , +and +.Fn wakeup_one +return the number of processes that were woken up. .Sh CODE REFERENCES These functions are implemented in the file .Pa sys/kern/kern_synch.c . Index: sys/kern/kern_synch.c =================================================================== RCS file: /cvs/src/sys/kern/kern_synch.c,v diff -u -p -r1.206 kern_synch.c --- sys/kern/kern_synch.c 23 Jul 2024 08:38:02 -0000 1.206 +++ sys/kern/kern_synch.c 17 Oct 2024 23:06:37 -0000 @@ -527,19 +527,18 @@ unsleep(struct proc *p) /* * Make a number of processes sleeping on the specified identifier runnable. */ -void +int wakeup_n(const volatile void *ident, int n) { - struct slpque *qp, wakeq; - struct proc *p; - struct proc *pnext; + struct slpque wakeq = TAILQ_HEAD_INITIALIZER(wakeq); + struct slpque *qp; + struct proc *p, *np; + int c = 0; - TAILQ_INIT(&wakeq); + qp = &slpque[LOOKUP(ident)]; SCHED_LOCK(); - qp = &slpque[LOOKUP(ident)]; - for (p = TAILQ_FIRST(qp); p != NULL && n != 0; p = pnext) { - pnext = TAILQ_NEXT(p, p_runq); + TAILQ_FOREACH_SAFE(p, qp, p_runq, np) { #ifdef DIAGNOSTIC if (p->p_stat != SSLEEP && p->p_stat != SSTOP) panic("thread %d p_stat is %d", p->p_tid, p->p_stat); @@ -550,7 +549,9 @@ wakeup_n(const volatile void *ident, int p->p_wchan = NULL; p->p_wmesg = NULL; TAILQ_INSERT_TAIL(&wakeq, p, p_runq); - --n; + + if (++c >= n) + break; } } while ((p = TAILQ_FIRST(&wakeq))) { @@ -561,15 +562,17 @@ wakeup_n(const volatile void *ident, int setrunnable(p); } SCHED_UNLOCK(); + + return (c); } /* * Make all processes sleeping on the specified identifier runnable. */ -void +int wakeup(const volatile void *chan) { - wakeup_n(chan, -1); + return wakeup_n(chan, INT_MAX); } int Index: sys/sys/systm.h =================================================================== RCS file: /cvs/src/sys/sys/systm.h,v diff -u -p -r1.171 systm.h --- sys/sys/systm.h 28 May 2024 12:50:23 -0000 1.171 +++ sys/sys/systm.h 17 Oct 2024 23:06:37 -0000 @@ -269,8 +269,8 @@ void cond_signal(struct cond *); struct mutex; struct rwlock; -void wakeup_n(const volatile void *, int); -void wakeup(const volatile void *); +int wakeup_n(const volatile void *, int); +int wakeup(const volatile void *); #define wakeup_one(c) wakeup_n((c), 1) int tsleep(const volatile void *, int, const char *, int); int tsleep_nsec(const volatile void *, int, const char *, uint64_t);