3
/********************************************************************
4
Create a new work queue. */
8
/*===================*/
11
ib_wqueue_t* wq = mem_alloc(sizeof(ib_wqueue_t));
13
mutex_create(&wq->mutex, SYNC_WORK_QUEUE);
15
wq->items = ib_list_create();
16
wq->event = os_event_create(NULL);
21
/********************************************************************
27
ib_wqueue_t* wq) /* in: work queue */
29
ut_a(!ib_list_get_first(wq->items));
31
mutex_free(&wq->mutex);
32
ib_list_free(wq->items);
33
os_event_free(wq->event);
38
/********************************************************************
39
Add a work item to the queue. */
44
ib_wqueue_t* wq, /* in: work queue */
45
void* item, /* in: work item */
46
mem_heap_t* heap) /* in: memory heap to use for allocating the
49
mutex_enter(&wq->mutex);
51
ib_list_add_last(wq->items, item, heap);
52
os_event_set(wq->event);
54
mutex_exit(&wq->mutex);
57
/********************************************************************
58
Wait for a work item to appear in the queue. */
63
ib_wqueue_t* wq) /* in: work queue */
68
os_event_wait(wq->event);
70
mutex_enter(&wq->mutex);
72
node = ib_list_get_first(wq->items);
75
ib_list_remove(wq->items, node);
77
if (!ib_list_get_first(wq->items)) {
78
/* We must reset the event when the list
80
os_event_reset(wq->event);
86
mutex_exit(&wq->mutex);
89
mutex_exit(&wq->mutex);