1
/*****************************************************************************
3
Copyright (C) 2006, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
19
#include "ut0wqueue.h"
21
/*******************************************************************//**
25
Created 4/26/2006 Osku Salerma
26
************************************************************************/
28
/****************************************************************//**
29
Create a new work queue.
33
ib_wqueue_create(void)
34
/*===================*/
36
ib_wqueue_t* wq = static_cast<ib_wqueue_t *>(mem_alloc(sizeof(ib_wqueue_t)));
38
/* Function ib_wqueue_create() has not been used anywhere,
39
not necessary to instrument this mutex */
40
mutex_create(PFS_NOT_INSTRUMENTED, &wq->mutex, SYNC_WORK_QUEUE);
42
wq->items = ib_list_create();
43
wq->event = os_event_create(NULL);
48
/****************************************************************//**
54
ib_wqueue_t* wq) /*!< in: work queue */
56
ut_a(!ib_list_get_first(wq->items));
58
mutex_free(&wq->mutex);
59
ib_list_free(wq->items);
60
os_event_free(wq->event);
65
/****************************************************************//**
66
Add a work item to the queue. */
71
ib_wqueue_t* wq, /*!< in: work queue */
72
void* item, /*!< in: work item */
73
mem_heap_t* heap) /*!< in: memory heap to use for allocating the
76
mutex_enter(&wq->mutex);
78
ib_list_add_last(wq->items, item, heap);
79
os_event_set(wq->event);
81
mutex_exit(&wq->mutex);
84
/****************************************************************//**
85
Wait for a work item to appear in the queue.
91
ib_wqueue_t* wq) /*!< in: work queue */
96
os_event_wait(wq->event);
98
mutex_enter(&wq->mutex);
100
node = ib_list_get_first(wq->items);
103
ib_list_remove(wq->items, node);
105
if (!ib_list_get_first(wq->items)) {
106
/* We must reset the event when the list
108
os_event_reset(wq->event);
114
mutex_exit(&wq->mutex);
117
mutex_exit(&wq->mutex);