bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC] kern: simple futex for gnumach (version 6)


From: Richard Braun
Subject: Re: [RFC] kern: simple futex for gnumach (version 6)
Date: Sat, 28 Dec 2013 11:52:55 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

On Sat, Dec 28, 2013 at 02:30:01AM +0100, Marin Ramesa wrote:
> On 12/27/2013 07:14:40 PM, Richard Braun wrote:
> >> +void futex_cross_address_space_wake(futex_t futex, boolean_t
> >wake_all)
> >> +{
> >> +  #define min(x, y) (x <= y ? x : y)
> >> +
> >> +  queue_iterate(&futex->chain, futex, futex_t, chain) {
> >> +
> >> +          simple_lock(&futex->futex_wait_lock);
> >> +
> >> +          int i;
> >> +
> >> +          for (i = 0; i < min(futex->num_futexed_threads,
> >> +                  ((futex_t)futex->chain.next)->num_futexed_threads); 
> >> i++) {
> >
> >If you have a list, you just walk it, there is no need to count the
> >number of items.
> 
> Threads are not in a list and I need to count the number of threads
> to use indexes for comparison of offsets.
> 
> >> +void futex_wake_threads(futex_t futex, boolean_t wake_all)
> >> +{
> >> +  if (wake_all) {
> >> +          int i;
> >> +          for (i = 0; i < futex->num_futexed_threads; i++)
> >> +                  futex_wake_one_thread(futex, i);
> >> +  } else
> >> +          futex_wake_one_thread(futex, futex->num_futexed_threads-1);
> >> +}
> >
> >What's the difference between this and
> >futex_cross_address_space_wake ??
> 
> futex_cross_address_space_wake() wakes all threads with the same
> offset. It
> doesn't matter in which futex they are in. This function is just for one
> futex, it doesn't matter which offsets the threads have.

Here is how it probably should be :

There should be one futex_waiter struct per thread, allocated on the
stack when a thread is about to wait. That structure is then queued on
the futex it's waiting for, using the address of the futex as the
wakeup event. When another thread wakes the futex, it walks the list
of futex_waiters, and for each of them, wakes up the associated thread.
No need to count anything here, just a simple list to walk, and no
need to have distinct cases between cross address space wakeups or not.
What makes a futex cross address space is simply that its a non first
class kernel object, just like ports, referenced with a (map, address)
pair. Once in the kernel, it's merely a wait queue.

-- 
Richard Braun



reply via email to

[Prev in Thread] Current Thread [Next in Thread]