[Top][All Lists]

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

Re: [PATCH 04/11] libports: lock-less reference counting for port_info o

From: Samuel Thibault
Subject: Re: [PATCH 04/11] libports: lock-less reference counting for port_info objects
Date: Tue, 13 May 2014 00:28:38 +0200
User-agent: Mutt/1.5.21+34 (58baf7c9f32f) (2010-12-30)

Justus Winter, le Mon 12 May 2014 12:05:42 +0200, a écrit :
> -  pthread_mutex_lock (&_ports_lock);
>    pthread_mutex_lock (&_ports_htable_lock);
>    if (_ports_htable.nr_items == 0)
> @@ -60,13 +59,12 @@ _ports_bucket_class_iterate (struct port_bucket *bucket,
>        if ((bucket == NULL || pi->bucket == bucket)
>            && (class == NULL || pi->class == class))
>       {
> -       pi->refcnt++;
> +       refcounts_ref (&pi->refcounts, NULL);
>         p[n] = pi;
>         n++;
>       }
>      }
>    pthread_mutex_unlock (&_ports_htable_lock);
> -  pthread_mutex_unlock (&_ports_lock);

Mmm, just to warn (I'm not sure I'll get the time soon to review these
changes), this kind of change needs a lot of making sure we see the
whole picture: quite often taking the mutex is not only to protect
the reference counting, but also to make that coherent with other
reads/writes, and thus only an atomic operation is not enough. As an
example, here we would want to make sure other threads see that we have
acquired a reference, before recording the pointer and doing something
else.  Keeping the mutex is more than we need, but we need to make sure
we still synchronize enough with the rest of the code.


reply via email to

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