1
/*****************************************************************************
3
Copyright (C) 1995, 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
/**************************************************//**
20
@file include/sync0arr.h
21
The wait array used in synchronization primitives
23
Created 9/5/1995 Heikki Tuuri
24
*******************************************************/
32
#include "os0thread.h"
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;
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 */
44
/*******************************************************************//**
45
Creates a synchronization wait array. It is protected by a mutex
46
which is automatically reserved when the functions operating on it
48
@return own: created wait array */
53
ulint n_cells, /*!< in: number of cells in the array
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. */
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. */
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. */
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
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. */
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. */
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 */
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. */
127
sync_array_t* arr); /*!< in: sync wait array */
128
/**********************************************************************//**
129
Prints info of the wait array. */
132
sync_array_print_info(
133
/*==================*/
134
FILE* file, /*!< in: file where to print */
135
sync_array_t* arr); /*!< in: wait array */
139
#include "sync0arr.ic"