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:
Adam Rutkowski 2019-04-17 23:05:24 -04:00
parent 121b3233e4
commit 407470c25d
2 changed files with 11 additions and 0 deletions

View File

@ -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);

View File

@ -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);