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