2 * event queue implementation.
4 * This code is licensed under the GNU LGPL, version 2.1 or later.
5 * See the COPYING.LIB file in the top-level directory.
8 #include "qemu-common.h"
9 #include "qemu-thread.h"
16 vevent_new(VEventType type, VReader *reader, VCard *card)
20 new_vevent = (VEvent *)qemu_malloc(sizeof(VEvent));
21 new_vevent->next = NULL;
22 new_vevent->type = type;
23 new_vevent->reader = vreader_reference(reader);
24 new_vevent->card = vcard_reference(card);
30 vevent_delete(VEvent *vevent)
35 vreader_free(vevent->reader);
36 vcard_free(vevent->card);
41 * VEvent queue management
44 static VEvent *vevent_queue_head;
45 static VEvent *vevent_queue_tail;
46 static QemuMutex vevent_queue_lock;
47 static QemuCond vevent_queue_condition;
49 void vevent_queue_init(void)
51 qemu_mutex_init(&vevent_queue_lock);
52 qemu_cond_init(&vevent_queue_condition);
53 vevent_queue_head = vevent_queue_tail = NULL;
57 vevent_queue_vevent(VEvent *vevent)
60 qemu_mutex_lock(&vevent_queue_lock);
61 if (vevent_queue_head) {
62 assert(vevent_queue_tail);
63 vevent_queue_tail->next = vevent;
65 vevent_queue_head = vevent;
67 vevent_queue_tail = vevent;
68 qemu_cond_signal(&vevent_queue_condition);
69 qemu_mutex_unlock(&vevent_queue_lock);
74 vevent_dequeue_vevent(void)
76 VEvent *vevent = NULL;
77 if (vevent_queue_head) {
78 vevent = vevent_queue_head;
79 vevent_queue_head = vevent->next;
85 VEvent *vevent_wait_next_vevent(void)
89 qemu_mutex_lock(&vevent_queue_lock);
90 while ((vevent = vevent_dequeue_vevent()) == NULL) {
91 qemu_cond_wait(&vevent_queue_condition, &vevent_queue_lock);
93 qemu_mutex_unlock(&vevent_queue_lock);
97 VEvent *vevent_get_next_vevent(void)
101 qemu_mutex_lock(&vevent_queue_lock);
102 vevent = vevent_dequeue_vevent();
103 qemu_mutex_unlock(&vevent_queue_lock);