~ubuntu-branches/ubuntu/trusty/drizzle/trusty

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