Add reference counter init routine
This is useful when reference counter is initialized in non-zeroed memory (or assuming atomic variable is not properly initialized by memseting to zero). Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
parent
121b3233e4
commit
407470c25d
@ -5,6 +5,14 @@
|
||||
|
||||
#include "../utils/utils_refcnt.h"
|
||||
|
||||
void ocf_refcnt_init(struct ocf_refcnt *rc)
|
||||
{
|
||||
env_atomic_set(&rc->counter, 0);
|
||||
env_atomic_set(&rc->freeze, 0);
|
||||
env_atomic_set(&rc->callback, 0);
|
||||
rc->cb = NULL;
|
||||
}
|
||||
|
||||
void ocf_refcnt_dec(struct ocf_refcnt *rc)
|
||||
{
|
||||
int val = env_atomic_dec_return(&rc->counter);
|
||||
|
@ -19,6 +19,9 @@ struct ocf_refcnt
|
||||
void *priv;
|
||||
};
|
||||
|
||||
/* Initialize reference counter */
|
||||
void ocf_refcnt_init(struct ocf_refcnt *rc);
|
||||
|
||||
/* Try to increment counter. Returns true if successfull, false if freezed */
|
||||
bool ocf_refcnt_inc(struct ocf_refcnt *rc);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user