~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
1
/*****************************************************************************
2
3
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
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
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
16
17
*****************************************************************************/
18
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
19
/******************************************************
20
The wait array used in synchronization primitives
21
22
Created 9/5/1995 Heikki Tuuri
23
*******************************************************/
24
25
#ifndef sync0arr_h
26
#define sync0arr_h
27
28
#include "univ.i"
29
#include "ut0lst.h"
30
#include "ut0mem.h"
31
#include "os0thread.h"
32
33
typedef struct sync_cell_struct		sync_cell_t;
34
typedef struct sync_array_struct	sync_array_t;
35
36
#define SYNC_ARRAY_OS_MUTEX	1
37
#define SYNC_ARRAY_MUTEX	2
38
39
/***********************************************************************
40
Creates a synchronization wait array. It is protected by a mutex
41
which is automatically reserved when the functions operating on it
42
are called. */
43
UNIV_INTERN
44
sync_array_t*
45
sync_array_create(
46
/*==============*/
47
				/* out, own: created wait array */
48
	ulint	n_cells,	/* in: number of cells in the array
49
				to create */
50
	ulint	protection);	/* in: either SYNC_ARRAY_OS_MUTEX or
51
				SYNC_ARRAY_MUTEX: determines the type
52
				of mutex protecting the data structure */
53
/**********************************************************************
54
Frees the resources in a wait array. */
55
UNIV_INTERN
56
void
57
sync_array_free(
58
/*============*/
59
	sync_array_t*	arr);	/* in, own: sync wait array */
60
/**********************************************************************
61
Reserves a wait array cell for waiting for an object.
62
The event of the cell is reset to nonsignalled state. */
63
UNIV_INTERN
64
void
65
sync_array_reserve_cell(
66
/*====================*/
67
	sync_array_t*	arr,	/* in: wait array */
68
	void*		object, /* in: pointer to the object to wait for */
69
	ulint		type,	/* in: lock request type */
70
	const char*	file,	/* in: file where requested */
71
	ulint		line,	/* in: line where requested */
72
	ulint*		index); /* out: index of the reserved cell */
73
/**********************************************************************
74
This function should be called when a thread starts to wait on
75
a wait array cell. In the debug version this function checks
76
if the wait for a semaphore will result in a deadlock, in which
77
case prints info and asserts. */
78
UNIV_INTERN
79
void
80
sync_array_wait_event(
81
/*==================*/
82
	sync_array_t*	arr,	/* in: wait array */
83
	ulint		index);	 /* in: index of the reserved cell */
84
/**********************************************************************
85
Frees the cell. NOTE! sync_array_wait_event frees the cell
86
automatically! */
87
UNIV_INTERN
88
void
89
sync_array_free_cell(
90
/*=================*/
91
	sync_array_t*	arr,	/* in: wait array */
92
	ulint		index);	/* in: index of the cell in array */
93
/**************************************************************************
94
Note that one of the wait objects was signalled. */
95
UNIV_INTERN
96
void
97
sync_array_object_signalled(
98
/*========================*/
99
	sync_array_t*	arr);	/* in: wait array */
100
/**************************************************************************
101
If the wakeup algorithm does not work perfectly at semaphore relases,
102
this function will do the waking (see the comment in mutex_exit). This
103
function should be called about every 1 second in the server. */
104
UNIV_INTERN
105
void
106
sync_arr_wake_threads_if_sema_free(void);
107
/*====================================*/
108
/**************************************************************************
109
Prints warnings of long semaphore waits to stderr. */
110
UNIV_INTERN
111
ibool
112
sync_array_print_long_waits(void);
113
/*=============================*/
114
			/* out: TRUE if fatal semaphore wait threshold
115
			was exceeded */
116
/************************************************************************
117
Validates the integrity of the wait array. Checks
118
that the number of reserved cells equals the count variable. */
119
UNIV_INTERN
120
void
121
sync_array_validate(
122
/*================*/
123
	sync_array_t*	arr);	/* in: sync wait array */
124
/**************************************************************************
125
Prints info of the wait array. */
126
UNIV_INTERN
127
void
128
sync_array_print_info(
129
/*==================*/
130
	FILE*		file,	/* in: file where to print */
131
	sync_array_t*	arr);	/* in: wait array */
132
133
134
#ifndef UNIV_NONINL
135
#include "sync0arr.ic"
136
#endif
137
138
#endif