Page MenuHomeFreeBSD

D54168.id168825.diff
No OneTemporary

D54168.id168825.diff

diff --git a/sys/dev/speaker/spkr.c b/sys/dev/speaker/spkr.c
--- 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 struct cdevsw spkr_cdevsw = {
.d_version = D_VERSION,
- .d_flags = D_NEEDGIANT,
.d_open = spkropen,
.d_close = spkrclose,
.d_write = spkrwrite,
@@ -71,23 +71,27 @@
(void) printf("tone: thz=%d centisecs=%d\n", thz, centisecs);
#endif /* DEBUG */
- /* set timer to generate clicks at given frequency in Hertz */
+ /*
+ * Acquire the i8254 clock, configure it to drive the speaker
+ * signal, and turn on the speaker.
+ */
if (timer_spkr_acquire()) {
- /* enter list of waiting procs ??? */
return;
}
- disable_intr();
+ /* Configure the speaker with the tone frequency. */
timer_spkr_setfreq(thz);
- enable_intr();
/*
- * Set timeout to endtone function, then give up the timeslice.
- * This is so other processes can execute while the tone is being
+ * Make the current thread sleep while the tone is being
* emitted.
*/
timo = centisecs * hz / 100;
if (timo > 0)
tsleep(&endtone, SPKRPRI | PCATCH, "spkrtn", timo);
+
+ /*
+ * Turn off the speaker and release the i8254 clock.
+ */
timer_spkr_release();
}
@@ -390,7 +394,7 @@
* 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
@@ -400,7 +404,7 @@
(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
@@ -408,7 +412,6 @@
#endif /* DEBUG */
playinit();
spkr_inbuf = malloc(DEV_BSIZE, M_SPKR, M_WAITOK);
- spkr_active = true;
return(0);
}
}
@@ -449,7 +452,7 @@
wakeup(&endtone);
wakeup(&endrest);
free(spkr_inbuf, M_SPKR);
- spkr_active = false;
+ (void) atomic_swap_int(&spkr_active, 0);
return(0);
}

File Metadata

Mime Type
text/plain
Expires
Thu, Jun 25, 1:40 AM (5 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34299495
Default Alt Text
D54168.id168825.diff (2 KB)

Event Timeline