Paul Cassella wrote:
> The sync variable version of the dmabuf code snippet (assuming the
> dmabuf_mutex is never acquired from an interrupt) would look like this:
>
> dmabuf_init(...);
> {
> ...
> spin_lock_init(&dmabuf_spin);
> sv_init(&dmabuf_sv, &dmabuf_spin, SV_MON_SPIN);
> ...
> }
>
> dmabuf_alloc(...)
> {
>
> ...
> while (1) {
> spin_lock(&dmabuf_spin);
> attempt to grab a free buffer;
> if (success){
> spin_unlock(&dmabuf_spin);
> return;
> } else {
> sv_wait(&dmabuf_sv);
> }
> }
> }
>
> dmabuf_free(...)
> {
> ...
> spin_lock(&dmabuf_spin);
> free up buffer;
> sv_broadcast(&dmabuf_sv);
> spin_unlock(&dmabuf_spin);
> }
>
But isn't this actually a simple situation? How about:
dmabuf_alloc(...)
{
...
while (1) {
spin_lock(&dmabuf_lock);
attempt to grab a free buffer;
spin_unlock(&dmabuf_lock);
if (success)
return;
down(&dmabuf_wait);
}
}
dmabuf_free(...)
{
...
spin_lock(&dmabuf_lock);
free up buffer;
spin_unlock(&dmabuf_lock);
up(&dmabuf_wait);
}
--
Daniel
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
Please read the FAQ at http://www.tux.org/lkml/