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