On Thu, 21 Dec 2017 10:26:15 -0700, Thomas Roell
<
grumpyo...@gmail.com> declaimed the
following:
>For a Mutex class, I'd suggest a priority inheritance based definition that
>cannot be locked. One of the biggies with Mutex design is lock/unlock
>order. I'd suggest adding semantics that enforce that the order for
>unlocking is exactly the reverse of the one for locking. This way a user
>can detect mistakes early on.
>
>In commercial project we do use a mutex hierachy, which means we disallow
>certain combinations of locks to avoid deadlocks (T0 owns A, now waits for
>B, while T1 owns B, but waits for A).
>
Unfortunately, deadlock avoidance is something that the programmer must
be able to analyze... Any software support will likely be so bloated it
makes the device unusable; or it will make use of more than one
lock/semaphore/mutex meaningless (if all attempts to lock C requires first
locking B and A, why bother?)
http://greenteapress.com/wp/semaphores/
(Consolidating from the last day or so) ISR should have nothing that
could involve locks -- what use is a "trylock()" going to be? If the ISR
couldn't gain the lock what will it do -- totally ignore the event that
triggered the ISR and return? Set a missed-interrupt flag and return
(basically the same as ignore the event, but defers notification to a
non-ISR routine)? Busy-wait -- in an ISR that should do minimal action and
return?
For an input device interrupt, the actions should probably be: test for
circular buffer full (if full, drop the data and set an overrun event
flag), if not full, insert data to next location and increment "next
pointer", set data-available flag.
Non-ISR thread reading available data tests for buffer empty (do
nothing) or pulls next data and increments read pointer. No locks really
needed as the ISR and reader never modify the same control values the
data-waiting flag may be the only risk -- it would be used to block the
reader from busy-looping when the reader has emptied the circular buffer.
But the event-flag code itself should probably disable interrupts for the
short period needed to set/clear the event flag, so again no overlapping
shared access.
Output device processing would be similar -- ISR (on device ready)
would pull data from circular buffer; non-ISR would fill buffer
--
Wulfraed Dennis Lee Bieber AF6VN
wlf...@ix.netcom.com HTTP://wlfraed.home.netcom.com/