bug-hurd
[Top][All Lists]
Advanced

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

Re: [PATCH 03/11] include: add lock-less reference counting primitives


From: Justus Winter
Subject: Re: [PATCH 03/11] include: add lock-less reference counting primitives
Date: Tue, 13 May 2014 12:50:54 +0200
User-agent: alot/0.3.4

Quoting Samuel Thibault (2014-05-13 01:04:13)
> Justus Winter, le Mon 12 May 2014 12:05:41 +0200, a écrit :
> > +/* An opaque type.  You must not access these values directly.  */
> > +typedef uint64_t refcounts_t;
> > +
> > +/* Instead, the functions manipulating refcounts_t values write the
> > +   results into this kind of objects.  */
> > +struct references {
> > +  uint32_t hard;
> > +  uint32_t weak;
> > +};
> > +
> > +union _references {
> > +  struct references refs;
> > +  refcounts_t rc;
> > +};
> > +
> > +/* Initialize REF with HARD and WEAK references.  */
> > +static inline void
> > +refcounts_init (refcounts_t *ref, uint32_t hard, uint32_t weak)
> > +{
> > +  ((union _references *) ref)->refs =
> 
> AIUI this cast is a case of type-puning.  Why not making refcounts_t the
> union itself?  That way would be clearly safe with gcc's extension.

As stated in the comment for refcounts_t, I like the idea of using the
type system to enforce the use of the accessor functions.

Justus



reply via email to

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