~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
1
/*****************************************************************************
2
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
3
Copyright (C) 2006, 2009, Innobase Oy. All Rights Reserved.
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
4
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.
8
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.
12
13
You should have received a copy of the GNU General Public License along with
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
16
17
*****************************************************************************/
18
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
19
#include "ut0wqueue.h"
20
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
21
/*******************************************************************//**
22
@file ut/ut0wqueue.c
23
A work queue
24
25
Created 4/26/2006 Osku Salerma
26
************************************************************************/
27
28
/****************************************************************//**
29
Create a new work queue.
30
@return	work queue */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
31
UNIV_INTERN
32
ib_wqueue_t*
33
ib_wqueue_create(void)
34
/*===================*/
35
{
2023.3.6 by Monty Taylor
Fixing some of the innodb c++ casting issues.
36
	ib_wqueue_t*	wq = static_cast<ib_wqueue_t *>(mem_alloc(sizeof(ib_wqueue_t)));
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
37
1819.7.68 by Stewart Smith
Merge initial InnoDB+ import.
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);
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
41
42
	wq->items = ib_list_create();
43
	wq->event = os_event_create(NULL);
44
45
	return(wq);
46
}
47
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
48
/****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
49
Free a work queue. */
50
UNIV_INTERN
51
void
52
ib_wqueue_free(
53
/*===========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
54
	ib_wqueue_t*	wq)	/*!< in: work queue */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
55
{
56
	ut_a(!ib_list_get_first(wq->items));
57
58
	mutex_free(&wq->mutex);
59
	ib_list_free(wq->items);
60
	os_event_free(wq->event);
61
62
	mem_free(wq);
63
}
64
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
65
/****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
66
Add a work item to the queue. */
67
UNIV_INTERN
68
void
69
ib_wqueue_add(
70
/*==========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
74
				list node */
75
{
76
	mutex_enter(&wq->mutex);
77
78
	ib_list_add_last(wq->items, item, heap);
79
	os_event_set(wq->event);
80
81
	mutex_exit(&wq->mutex);
82
}
83
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
84
/****************************************************************//**
85
Wait for a work item to appear in the queue.
86
@return	work item */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
87
UNIV_INTERN
88
void*
89
ib_wqueue_wait(
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
90
/*===========*/
91
	ib_wqueue_t*	wq)	/*!< in: work queue */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
92
{
93
	ib_list_node_t*	node;
94
95
	for (;;) {
96
		os_event_wait(wq->event);
97
98
		mutex_enter(&wq->mutex);
99
100
		node = ib_list_get_first(wq->items);
101
102
		if (node) {
103
			ib_list_remove(wq->items, node);
104
105
			if (!ib_list_get_first(wq->items)) {
106
				/* We must reset the event when the list
107
				gets emptied. */
108
				os_event_reset(wq->event);
109
			}
110
111
			break;
112
		}
113
114
		mutex_exit(&wq->mutex);
115
	}
116
117
	mutex_exit(&wq->mutex);
118
119
	return(node->data);
120
}