Re: [PATCH] Futexes IV (Fast Lightweight Userspace Semaphores)

Martin Wirth
2002-03-26T08:19:25Z

>
> And on top of them:
> futex_down(struct futex *);
> futex_up(struct futex *);
>
Why not keep the simple one-sys-call interface for the fuxtexes. The
code is so small that it is
not worth to delete it.

>
>
>int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
>{
> int ret, saved_errno;
>
> uwaitq_add(cond);
> futex_up(&mutex);
> while ((ret = uwaitq_wait(NULL)) == 0 || errno == EINTR);
> saved_errno = errno;
> uwaitq_remove(cond);
> futex_down(&mutex);
>
You should loop here in order catch signals:

while ( futex_down(&mutex) < 0 && errno == EINTR)

>
> if (ret < 0 && errno == EINTR)
> goto again;
>
This assumes that you are allowed to do a double uwaitq_add.

>
> saved_errno = errno;
> uwaitq_remove(cond);
> futex_down(&mutex);
>
Also loop here

>
> errno = saved_errno;
>
> return ret;
>}
>
Now whats interesting is the kernel part. I must admit that I haven't
fully understood all
effects of the double use of the cookie in your first implementation.
But if you use a memory
location as identifier you have to keep a separate flag within
uwaitq_head that is zeroed
before you add to the waitqueue and set by the signal functions. Then
uwaitq_wait has to check for it.
This is necessary in order not to loose a wakeup while you are on the
queue but not sleeping.

uwaitq_remove also takes an argument, are you heading for waiting on
multiple events?

Since you need to pin down the page between uwaitq_add and uwaitq_remove
you will have to limit
the number of simultaneous add calls. Should this be configurable?

Cheers,
Martin