From 407470c25d33ac7bb1132a6c84b5481091fa32b5 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Wed, 17 Apr 2019 23:05:24 -0400 Subject: [PATCH] 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 --- src/utils/utils_refcnt.c | 8 ++++++++ src/utils/utils_refcnt.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/src/utils/utils_refcnt.c b/src/utils/utils_refcnt.c index 045e952..450092a 100644 --- a/src/utils/utils_refcnt.c +++ b/src/utils/utils_refcnt.c @@ -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); diff --git a/src/utils/utils_refcnt.h b/src/utils/utils_refcnt.h index 5df2714..10bb24b 100644 --- a/src/utils/utils_refcnt.h +++ b/src/utils/utils_refcnt.h @@ -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);