diff options
author | 2019-12-22 19:11:45 +0000 | |
---|---|---|
committer | 2019-12-22 19:11:45 +0000 | |
commit | a3a673009a1f31eac7a6366ab3469739c1e30d6d (patch) | |
tree | 84daa5d86097559f4bb913ac9bf8084573665ec0 /sys | |
parent | regen (diff) | |
download | wireguard-openbsd-a3a673009a1f31eac7a6366ab3469739c1e30d6d.tar.xz wireguard-openbsd-a3a673009a1f31eac7a6366ab3469739c1e30d6d.zip |
midi(4): *sleep(9) -> *sleep_nsec(9)
These are straightforward except for the tsleep(9) conversion. ratchov@
had a bit to say about that code:
https://marc.info/?l=openbsd-tech&m=157665936017373&w=2
> The problem is that close(2) may reset the transmitter before the few
> bytes of its internal buffer is sent on the wire; there's no "wait for
> completion" feature in such simple hardware, so we just wait few
> milliseconds.
>
> The transmitter buffer size is around 16 bytes, the byte rate is 3125
> bytes/second. So if we wait at least 16B / 3125B/s = 5.12ms, we're
> safe. Waiting 10ms-20ms is enough and is unnoticeable.
Hence, in this diff we wait a flat 20ms in that situation.
ok ratchov@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/midi.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/sys/dev/midi.c b/sys/dev/midi.c index 19d7017e955..15713cecc51 100644 --- a/sys/dev/midi.c +++ b/sys/dev/midi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: midi.c,v 1.43 2017/07/19 22:23:54 kettenis Exp $ */ +/* $OpenBSD: midi.c,v 1.44 2019/12/22 19:11:45 cheloha Exp $ */ /* * Copyright (c) 2003, 2004 Alexandre Ratchov @@ -126,7 +126,8 @@ midiread(dev_t dev, struct uio *uio, int ioflag) goto done_mtx; } sc->rchan = 1; - error = msleep(&sc->rchan, &audio_lock, PWAIT | PCATCH, "mid_rd", 0); + error = msleep_nsec(&sc->rchan, &audio_lock, PWAIT | PCATCH, + "mid_rd", INFSLP); if (!(sc->dev.dv_flags & DVF_ACTIVE)) error = EIO; if (error) @@ -270,8 +271,8 @@ midiwrite(dev_t dev, struct uio *uio, int ioflag) goto done_mtx; } sc->wchan = 1; - error = msleep(&sc->wchan, &audio_lock, - PWAIT | PCATCH, "mid_wr", 0); + error = msleep_nsec(&sc->wchan, &audio_lock, + PWAIT | PCATCH, "mid_wr", INFSLP); if (!(sc->dev.dv_flags & DVF_ACTIVE)) error = EIO; if (error) @@ -476,8 +477,8 @@ midiclose(dev_t dev, int fflag, int devtype, struct proc *p) midi_out_start(sc); while (sc->isbusy) { sc->wchan = 1; - error = msleep(&sc->wchan, &audio_lock, - PWAIT, "mid_dr", 5 * hz); + error = msleep_nsec(&sc->wchan, &audio_lock, + PWAIT, "mid_dr", SEC_TO_NSEC(5)); if (!(sc->dev.dv_flags & DVF_ACTIVE)) error = EIO; if (error) @@ -492,7 +493,7 @@ midiclose(dev_t dev, int fflag, int devtype, struct proc *p) * sleep 20ms (around 64 bytes) to give the time to the * uart to drain its internal buffers. */ - tsleep(&sc->wchan, PWAIT, "mid_cl", hz * MIDI_MAXWRITE / MIDI_RATE); + tsleep_nsec(&sc->wchan, PWAIT, "mid_cl", MSEC_TO_NSEC(20)); sc->hw_if->close(sc->hw_hdl); sc->flags = 0; device_unref(&sc->dev); |