[PATCH v3 03/19] net/intel/common: add utility functions

Burakov, Anatoly anatoly.burakov at intel.com
Fri Sep 18 11:20:50 CEST 2026


On 9/17/2026 2:30 AM, Stephen Hemminger wrote:
> On Wed, 16 Sep 2026 13:18:09 +0100
> Anatoly Burakov <anatoly.burakov at intel.com> wrote:
> 
>> +/*
>> + * Simplistic reference counter. Not thread-safe, not atomic.
>> + */
>> +struct ci_refcount {
>> +	uint32_t count;
>> +};
>> +
>> +/**
>> + * Take a reference. Returns true if this is the first reference.
>> + *
>> + * @param ref
>> + *   Reference count to acquire.
>> + * @return
>> + *   true if this is the first reference, false otherwise.
>> + */
>> +static inline bool
>> +ci_refcount_acquire(struct ci_refcount *ref)
>> +{
>> +#ifdef CI_DEBUG
>> +	if (ref->count == UINT32_MAX)
>> +		rte_panic("ci_refcount overflow\n");
>> +#endif
>> +	return ref->count++ == 0;
>> +}
>> +
> 
> Would it help if EAL has a generic refcount?
> I would make the refcount overflow/underflow still fatal, should never happen.

In the next revision I changed the name to `ci_usage_count_t` which is a 
more descriptive name than a refcount (less connotations), and made it a 
direct uint32_t instead of a struct.

It would be nice to have this in EAL, but I'm not sure of the scope of 
such work and what sort of use cases should this cover. It can be 
promoted to EAL later if you think it's worth doing, and I'll gladly 
submit a patch for the next release and we can work both towards 
defining what sorts of use cases we want to cover and convert the 
codebase to use those, but I would defer it to next release.

-- 
Thanks,
Anatoly


More information about the dev mailing list