diff options
| author | Raphael 'kena' Poss <knz@thaumogen.net> | 2026-01-01 16:34:44 +0000 |
|---|---|---|
| committer | Warner Losh <imp@FreeBSD.org> | 2026-04-24 16:23:06 +0000 |
| commit | a80ec2b51ac6b8f2588b927913e40c7a3d2862e6 (patch) | |
| tree | 7182d4c0a9108354265fb3247a608b4cda9f5416 | |
| parent | 43b7cf42d425abc84a1313b7eed933438804a051 (diff) | |
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
| -rw-r--r-- | sys/dev/speaker/spkr.c | 9 |
1 files 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); } |
