On Wed, 1 Jun 2022 08:19:54 +0000
Mattias Rönnblom <mattias.ronnb...@ericsson.com> wrote:

> On 2022-06-01 00:45, Stephen Hemminger wrote:
> > On Mon, 23 May 2022 16:23:46 +0200
> > Mattias Rönnblom <mattias.ronnb...@ericsson.com> wrote:
> >   
> >> +/**
> >> + * The RTE seqcount type.
> >> + */
> >> +typedef struct {
> >> +  uint32_t sn; /**< A sequence number for the protected data. */
> >> +} rte_seqcount_t;  
> > 
> > Don't need structure for only one element.
> >   
> 
> The struct adds a degree of type safety, with no run-time cost.

Makes sense.

> 
> > typedef uint32_t rte_seqcount_t;
> > 
> > +   if (unlikely(begin_sn != end_sn))
> > +           return true;
> > +
> > +   return false;
> > 
> > Prefer to avoid conditional if possible (compiler will optimize it as):
> > 
> >          return begin_sn == end_sn;  
> 
> Is this a readability argument, or a performance one?
> 
> The compiler might use the unlikely hint to do something useful, like 
> avoiding a branch in the common case.

It is a matter of taste. I always prefer writing the smallest (within reason)
amount of code as possible. And my preference is to do things with declarative
and data statements rather than conditionals.

Reply via email to