mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-07-04 02:56:52 +00:00
dm: mei: add reference counter functions
mei handles objects on the list, hence reference counting infrastructure is required for easier multithreading. Tracked-On: #1536 Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Acked-by: Wang, Yu1 <yu1.wang@intel.com>
This commit is contained in:
parent
6a96878e0b
commit
b8d53d17d5
@ -129,3 +129,20 @@ static int guid_unparse(const guid_t *guid, char *str, size_t len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct refcnt {
|
||||
void (*destroy)(const struct refcnt *ref);
|
||||
int count;
|
||||
};
|
||||
|
||||
static inline void
|
||||
refcnt_get(const struct refcnt *ref)
|
||||
{
|
||||
__sync_add_and_fetch((int *)&ref->count, 1);
|
||||
}
|
||||
|
||||
static inline void
|
||||
refcnt_put(const struct refcnt *ref)
|
||||
{
|
||||
if (__sync_sub_and_fetch((int *)&ref->count, 1) == 0)
|
||||
ref->destroy(ref);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user