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:
Tomas Winkler 2018-10-15 21:41:56 +03:00 committed by wenlingz
parent 6a96878e0b
commit b8d53d17d5

View File

@ -129,3 +129,20 @@ static int guid_unparse(const guid_t *guid, char *str, size_t len)
return 0; 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);
}