1
/******************************************************
2
The wait array used in synchronization primitives
6
Created 9/5/1995 Heikki Tuuri
7
*******************************************************/
15
#include "os0thread.h"
17
typedef struct sync_cell_struct sync_cell_t;
18
typedef struct sync_array_struct sync_array_t;
20
#define SYNC_ARRAY_OS_MUTEX 1
21
#define SYNC_ARRAY_MUTEX 2
23
/***********************************************************************
24
Creates a synchronization wait array. It is protected by a mutex
25
which is automatically reserved when the functions operating on it
31
/* out, own: created wait array */
32
ulint n_cells, /* in: number of cells in the array
34
ulint protection); /* in: either SYNC_ARRAY_OS_MUTEX or
35
SYNC_ARRAY_MUTEX: determines the type
36
of mutex protecting the data structure */
37
/**********************************************************************
38
Frees the resources in a wait array. */
43
sync_array_t* arr); /* in, own: sync wait array */
44
/**********************************************************************
45
Reserves a wait array cell for waiting for an object.
46
The event of the cell is reset to nonsignalled state. */
49
sync_array_reserve_cell(
50
/*====================*/
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
/**********************************************************************
58
This function should be called when a thread starts to wait on
59
a wait array cell. In the debug version this function checks
60
if the wait for a semaphore will result in a deadlock, in which
61
case prints info and asserts. */
64
sync_array_wait_event(
65
/*==================*/
66
sync_array_t* arr, /* in: wait array */
67
ulint index); /* in: index of the reserved cell */
68
/**********************************************************************
69
Frees the cell safely by reserving the sync array mutex and decrementing
70
n_reserved if necessary. Should only be called from mutex_spin_wait. */
73
sync_array_free_cell_protected(
74
/*===========================*/
75
sync_array_t* arr, /* in: wait array */
76
ulint index); /* in: index of the cell in array */
77
/**************************************************************************
78
Looks for the cells in the wait array which refer
79
to the wait object specified,
80
and sets their corresponding events to the signaled state. In this
81
way releases the threads waiting for the object to contend for the object.
82
It is possible that no such cell is found, in which case does nothing. */
85
sync_array_signal_object(
86
/*=====================*/
87
sync_array_t* arr, /* in: wait array */
88
void* object);/* in: wait object */
89
/**************************************************************************
90
If the wakeup algorithm does not work perfectly at semaphore relases,
91
this function will do the waking (see the comment in mutex_exit). This
92
function should be called about every 1 second in the server. */
95
sync_arr_wake_threads_if_sema_free(void);
96
/*====================================*/
97
/**************************************************************************
98
Prints warnings of long semaphore waits to stderr. */
101
sync_array_print_long_waits(void);
102
/*=============================*/
103
/* out: TRUE if fatal semaphore wait threshold
105
/************************************************************************
106
Validates the integrity of the wait array. Checks
107
that the number of reserved cells equals the count variable. */
112
sync_array_t* arr); /* in: sync wait array */
113
/**************************************************************************
114
Prints info of the wait array. */
117
sync_array_print_info(
118
/*==================*/
119
FILE* file, /* in: file where to print */
120
sync_array_t* arr); /* in: wait array */
124
#include "sync0arr.ic"