~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/ut/ut0wqueue.c

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "ut0wqueue.h"
 
2
 
 
3
/********************************************************************
 
4
Create a new work queue. */
 
5
 
 
6
ib_wqueue_t*
 
7
ib_wqueue_create(void)
 
8
/*===================*/
 
9
                        /* out: work queue */
 
10
{
 
11
        ib_wqueue_t*    wq = mem_alloc(sizeof(ib_wqueue_t));
 
12
 
 
13
        mutex_create(&wq->mutex, SYNC_WORK_QUEUE);
 
14
 
 
15
        wq->items = ib_list_create();
 
16
        wq->event = os_event_create(NULL);
 
17
 
 
18
        return(wq);
 
19
}
 
20
 
 
21
/********************************************************************
 
22
Free a work queue. */
 
23
 
 
24
void
 
25
ib_wqueue_free(
 
26
/*===========*/
 
27
        ib_wqueue_t*    wq)     /* in: work queue */
 
28
{
 
29
        ut_a(!ib_list_get_first(wq->items));
 
30
 
 
31
        mutex_free(&wq->mutex);
 
32
        ib_list_free(wq->items);
 
33
        os_event_free(wq->event);
 
34
 
 
35
        mem_free(wq);
 
36
}
 
37
 
 
38
/********************************************************************
 
39
Add a work item to the queue. */
 
40
 
 
41
void
 
42
ib_wqueue_add(
 
43
/*==========*/
 
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
 
47
                                list node */
 
48
{
 
49
        mutex_enter(&wq->mutex);
 
50
 
 
51
        ib_list_add_last(wq->items, item, heap);
 
52
        os_event_set(wq->event);
 
53
 
 
54
        mutex_exit(&wq->mutex);
 
55
}
 
56
 
 
57
/********************************************************************
 
58
Wait for a work item to appear in the queue. */
 
59
 
 
60
void*
 
61
ib_wqueue_wait(
 
62
                                /* out: work item */
 
63
        ib_wqueue_t*    wq)     /* in: work queue */
 
64
{
 
65
        ib_list_node_t* node;
 
66
 
 
67
        for (;;) {
 
68
                os_event_wait(wq->event);
 
69
 
 
70
                mutex_enter(&wq->mutex);
 
71
 
 
72
                node = ib_list_get_first(wq->items);
 
73
 
 
74
                if (node) {
 
75
                        ib_list_remove(wq->items, node);
 
76
 
 
77
                        if (!ib_list_get_first(wq->items)) {
 
78
                                /* We must reset the event when the list
 
79
                                gets emptied. */
 
80
                                os_event_reset(wq->event);
 
81
                        }
 
82
 
 
83
                        break;
 
84
                }
 
85
 
 
86
                mutex_exit(&wq->mutex);
 
87
        }
 
88
 
 
89
        mutex_exit(&wq->mutex);
 
90
 
 
91
        return(node->data);
 
92
}