]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | /* |
2 | * Copyright(c) 2019 Intel Corporation | |
3 | * SPDX-License-Identifier: BSD-3-Clause-Clear | |
4 | */ | |
5 | ||
6 | #ifndef __OCF_REFCNT_H__ | |
7 | #define __OCF_REFCNT_H__ | |
8 | ||
9 | #include "ocf_env.h" | |
10 | ||
11 | typedef void (*ocf_refcnt_cb_t)(void *priv); | |
12 | ||
13 | struct ocf_refcnt | |
14 | { | |
15 | env_atomic counter; | |
16 | env_atomic freeze; | |
17 | env_atomic callback; | |
18 | ocf_refcnt_cb_t cb; | |
19 | void *priv; | |
20 | }; | |
21 | ||
22 | /* Initialize reference counter */ | |
23 | void ocf_refcnt_init(struct ocf_refcnt *rc); | |
24 | ||
f67539c2 TL |
25 | /* Try to increment counter. Returns counter value (> 0) if successfull, 0 |
26 | * if counter is frozen */ | |
27 | int ocf_refcnt_inc(struct ocf_refcnt *rc); | |
9f95a23c | 28 | |
f67539c2 TL |
29 | /* Decrement reference counter and return post-decrement value */ |
30 | int ocf_refcnt_dec(struct ocf_refcnt *rc); | |
9f95a23c TL |
31 | |
32 | /* Disallow incrementing of underlying counter - attempts to increment counter | |
33 | * will be failing until ocf_refcnt_unfreeze is calleed. | |
f67539c2 | 34 | * It's ok to call freeze multiple times, in which case counter is frozen |
9f95a23c TL |
35 | * until all freeze calls are offset by a corresponding unfreeze.*/ |
36 | void ocf_refcnt_freeze(struct ocf_refcnt *rc); | |
37 | ||
38 | /* Cancel the effect of single ocf_refcnt_freeze call */ | |
39 | void ocf_refcnt_unfreeze(struct ocf_refcnt *rc); | |
40 | ||
f67539c2 TL |
41 | bool ocf_refcnt_frozen(struct ocf_refcnt *rc); |
42 | ||
9f95a23c | 43 | /* Register callback to be called when reference counter drops to 0. |
f67539c2 | 44 | * Must be called after counter is frozen. |
9f95a23c TL |
45 | * Cannot be called until previously regsitered callback had fired. */ |
46 | void ocf_refcnt_register_zero_cb(struct ocf_refcnt *rc, ocf_refcnt_cb_t cb, | |
47 | void *priv); | |
48 | ||
49 | #endif // __OCF_REFCNT_H__ |