Re: wait_event_interruptible() seems non-atomic
From: Manfred Spraul
Date: Sat Nov 20 2004 - 11:18:24 EST
Hi Jan,
I would like to also lock Buffer_lock around BufRP != BufWP, but don't see a
way on how to accomplish this.
This is not a problem: You compare BufRP and BufWP twice: once within
wait_event_interruptible (without locking) and again a second test in
your uif_read function with locking.
You are right that the test within wait_event_interruptible is
optimistic: a concurrent uif_read could read the new data before the
initial uif_read has a chance to acquire the BufferLock. But it doesn't
matter: AFAICS the test is optimistic, it can't happen that BufRP and WP
are actually different and wait_event sleeps. And the external loop
within uif_read() just loops if the race that you describe happened.
Btw, could you post a link to the complete driver when asking questions?
For example the use of down_interruptible() looks wrong to me, I'd use
plain down().
--
Manfred
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/