Date: Fri, 24 Apr 2026 16:24:45 +0000 From: Warner Losh <imp@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Raphael 'kena' Poss <knz@thaumogen.net> Subject: git: a80ec2b51ac6 - main - speaker(4): make spkropen thread-safe Message-ID: <69eb994d.3a5d7.3e0b30d5@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=a80ec2b51ac6b8f2588b927913e40c7a3d2862e6 commit a80ec2b51ac6b8f2588b927913e40c7a3d2862e6 Author: Raphael 'kena' Poss <knz@thaumogen.net> AuthorDate: 2026-01-01 16:34:44 +0000 Commit: Warner Losh <imp@FreeBSD.org> CommitDate: 2026-04-24 16:23:06 +0000 speaker(4): make spkropen thread-safe Signed-off-by: Raphael Poss <knz@thaumogen.net> Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1922 --- sys/dev/speaker/spkr.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/sys/dev/speaker/spkr.c b/sys/dev/speaker/spkr.c index 85789c107336..85a0c837f4b4 100644 --- a/sys/dev/speaker/spkr.c +++ b/sys/dev/speaker/spkr.c @@ -14,6 +14,7 @@ #include <sys/conf.h> #include <sys/ctype.h> #include <sys/malloc.h> +#include <machine/atomic.h> #include <machine/clock.h> #include <dev/speaker/speaker.h> @@ -24,7 +25,6 @@ static d_ioctl_t spkrioctl; static struct cdevsw spkr_cdevsw = { .d_version = D_VERSION, - .d_flags = 0, .d_open = spkropen, .d_close = spkrclose, .d_write = spkrwrite, @@ -394,7 +394,7 @@ playstring(char *cp, size_t slen) * endtone(), and rest() functions defined above. */ -static bool spkr_active = false; /* exclusion flag */ +static int spkr_active = 0; /* exclusion flag */ static char *spkr_inbuf; /* incoming buf */ static int @@ -404,7 +404,7 @@ spkropen(struct cdev *dev, int flags, int fmt, struct thread *td) (void) printf("spkropen: entering with dev = %s\n", devtoname(dev)); #endif /* DEBUG */ - if (spkr_active) + if (!atomic_cmpset_int(&spkr_active, 0, 1)) return(EBUSY); else { #ifdef DEBUG @@ -412,7 +412,6 @@ spkropen(struct cdev *dev, int flags, int fmt, struct thread *td) #endif /* DEBUG */ playinit(); spkr_inbuf = malloc(DEV_BSIZE, M_SPKR, M_WAITOK); - spkr_active = true; return(0); } } @@ -453,7 +452,7 @@ spkrclose(struct cdev *dev, int flags, int fmt, struct thread *td) wakeup(&endtone); wakeup(&endrest); free(spkr_inbuf, M_SPKR); - spkr_active = false; + (void) atomic_swap_int(&spkr_active, 0); return(0); }home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69eb994d.3a5d7.3e0b30d5>
