mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 07:43:54 -06:00
hw/rdma: Introduce protected qlist
To make code more readable move handling of protected list to a rdma_utils Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com> Reviewed-by: Marcel Apfelbaum <marcel.apfelbaum@gmail.com> Message-Id: <1552300155-25216-3-git-send-email-yuval.shaia@oracle.com> Reviewed-by: Kamal Heib <kamalheib1@gmail.com> Signed-off-by: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
This commit is contained in:
parent
4d71b38ae8
commit
b20fc79510
4 changed files with 55 additions and 21 deletions
|
@ -14,6 +14,8 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qapi/qmp/qlist.h"
|
||||
#include "qapi/qmp/qnum.h"
|
||||
#include "trace.h"
|
||||
#include "rdma_utils.h"
|
||||
|
||||
|
@ -51,3 +53,40 @@ void rdma_pci_dma_unmap(PCIDevice *dev, void *buffer, dma_addr_t len)
|
|||
pci_dma_unmap(dev, buffer, len, DMA_DIRECTION_TO_DEVICE, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void rdma_protected_qlist_init(RdmaProtectedQList *list)
|
||||
{
|
||||
qemu_mutex_init(&list->lock);
|
||||
list->list = qlist_new();
|
||||
}
|
||||
|
||||
void rdma_protected_qlist_destroy(RdmaProtectedQList *list)
|
||||
{
|
||||
if (list->list) {
|
||||
qlist_destroy_obj(QOBJECT(list->list));
|
||||
qemu_mutex_destroy(&list->lock);
|
||||
list->list = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void rdma_protected_qlist_append_int64(RdmaProtectedQList *list, int64_t value)
|
||||
{
|
||||
qemu_mutex_lock(&list->lock);
|
||||
qlist_append_int(list->list, value);
|
||||
qemu_mutex_unlock(&list->lock);
|
||||
}
|
||||
|
||||
int64_t rdma_protected_qlist_pop_int64(RdmaProtectedQList *list)
|
||||
{
|
||||
QObject *obj;
|
||||
|
||||
qemu_mutex_lock(&list->lock);
|
||||
obj = qlist_pop(list->list);
|
||||
qemu_mutex_unlock(&list->lock);
|
||||
|
||||
if (!obj) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
return qnum_get_uint(qobject_to(QNum, obj));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue