~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/innodb_plugin/include/sync0arr.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

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