lkml.org 
[lkml]   [2020]   [Oct]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: drivers/block/rbd.c: atomic_inc_return_safe() & atomic_dec_return_safe()
From
Date
On 10/2/20 4:34 PM, Shuah Khan wrote:
> All,
>
> I came across these atomic_inc_return_safe() & atomic_dec_return_safe()
> functions that hold the counters at safe values.
>
> atomic_inc_return_safe()
>
> If the counter is already 0 it will not be incremented.
> If the counter is already at its maximum value returns
> -EINVAL without updating it.
>
> atomic_dec_return_safe()
>
> Decrement the counter. Return the resulting value, or -EINVAL
>
> These two routines are static and only used in rbd.c.
>
> Can these become part of atomic_t ops?

I think you just want to use refcount_t for this use case. They
have safe guards for under/overflow.

--
Jens Axboe

\
 
 \ /
  Last update: 2020-10-03 01:45    [W:0.031 / U:0.284 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site