On 16.03.2023 14:54, Roger Pau Monné wrote:
> On Tue, Mar 14, 2023 at 08:56:29PM +0000, Volodymyr Babchuk wrote:
>> --- /dev/null
>> +++ b/xen/include/xen/refcnt.h
>> @@ -0,0 +1,59 @@
> 
> This seems to be missing some kind of license, can we have an SPDX tag
> at least?

Not "at least", but strictly that way for any new code. Patches to convert
various existing code to SPDX are already pending iirc.

>> +#ifndef __XEN_REFCNT_H__
>> +#define __XEN_REFCNT_H__
>> +
>> +#include <asm/atomic.h>
>> +#include <asm/bug.h>
>> +
>> +#define REFCNT_SATURATED (INT_MIN / 2)
>> +
>> +typedef struct {
>> +    atomic_t refcnt;
>> +} refcnt_t;
>> +
>> +static inline void refcnt_init(refcnt_t *refcnt)
>> +{
>> +    atomic_set(&refcnt->refcnt, 1);
>> +}
>> +
>> +static inline int refcnt_read(refcnt_t *refcnt)
> 
> const.
> 
>> +{
>> +    return atomic_read(&refcnt->refcnt);
>> +}
>> +
>> +static inline void refcnt_get(refcnt_t *refcnt)
>> +{
>> +    int old = atomic_add_unless(&refcnt->refcnt, 1, 0);
>> +
>> +    if ( unlikely(old < 0) || unlikely (old + 1 < 0) )
>                                          ^ extra space
> 
> You want a single unlikely for both conditions.

Are you sure? My experience was generally the other way around: likely()
and unlikely() become ineffectual as soon as the compiler needs more
than one branch for the inner construct (ie generally for and && or ||).

Jan

Reply via email to