git: a80ec2b51ac6 - main - speaker(4): make spkropen thread-safe
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 24 Apr 2026 16:24:45 UTC
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);
}