lkml.org 
[lkml]   [2000]   [Dec]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC] Semaphores used for daemon wakeup
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 majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 12:52    [W:0.051 / U:7.116 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site