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 "glib-compat.h"
15 vevent_new(VEventType type
, VReader
*reader
, VCard
*card
)
19 new_vevent
= g_new(VEvent
, 1);
20 new_vevent
->next
= NULL
;
21 new_vevent
->type
= type
;
22 new_vevent
->reader
= vreader_reference(reader
);
23 new_vevent
->card
= vcard_reference(card
);
29 vevent_delete(VEvent
*vevent
)
34 vreader_free(vevent
->reader
);
35 vcard_free(vevent
->card
);
40 * VEvent queue management
43 static VEvent
*vevent_queue_head
;
44 static VEvent
*vevent_queue_tail
;
45 static CompatGMutex vevent_queue_lock
;
46 static CompatGCond vevent_queue_condition
;
48 void vevent_queue_init(void)
50 vevent_queue_head
= vevent_queue_tail
= NULL
;
54 vevent_queue_vevent(VEvent
*vevent
)
57 g_mutex_lock(&vevent_queue_lock
);
58 if (vevent_queue_head
) {
59 assert(vevent_queue_tail
);
60 vevent_queue_tail
->next
= vevent
;
62 vevent_queue_head
= vevent
;
64 vevent_queue_tail
= vevent
;
65 g_cond_signal(&vevent_queue_condition
);
66 g_mutex_unlock(&vevent_queue_lock
);
71 vevent_dequeue_vevent(void)
73 VEvent
*vevent
= NULL
;
74 if (vevent_queue_head
) {
75 vevent
= vevent_queue_head
;
76 vevent_queue_head
= vevent
->next
;
82 VEvent
*vevent_wait_next_vevent(void)
86 g_mutex_lock(&vevent_queue_lock
);
87 while ((vevent
= vevent_dequeue_vevent()) == NULL
) {
88 g_cond_wait(&vevent_queue_condition
, &vevent_queue_lock
);
90 g_mutex_unlock(&vevent_queue_lock
);
94 VEvent
*vevent_get_next_vevent(void)
98 g_mutex_lock(&vevent_queue_lock
);
99 vevent
= vevent_dequeue_vevent();
100 g_mutex_unlock(&vevent_queue_lock
);