Skip to content

Commit b8d53d1

Browse files
Tomas Winklerwenlingz
authored andcommitted
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>
1 parent 6a96878 commit b8d53d1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

devicemodel/hw/pci/virtio/virtio_mei.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,20 @@ static int guid_unparse(const guid_t *guid, char *str, size_t len)
129129
return 0;
130130
}
131131

132+
struct refcnt {
133+
void (*destroy)(const struct refcnt *ref);
134+
int count;
135+
};
136+
137+
static inline void
138+
refcnt_get(const struct refcnt *ref)
139+
{
140+
__sync_add_and_fetch((int *)&ref->count, 1);
141+
}
142+
143+
static inline void
144+
refcnt_put(const struct refcnt *ref)
145+
{
146+
if (__sync_sub_and_fetch((int *)&ref->count, 1) == 0)
147+
ref->destroy(ref);
148+
}

0 commit comments

Comments
 (0)