MySQL 5.6.14 Source Code Document
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
waiting_threads.h
1
/* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
2
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
6
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
11
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15
16
#ifndef _waiting_threads_h
17
#define _waiting_threads_h
18
19
#include <my_global.h>
20
#include <my_sys.h>
21
22
#include <lf.h>
23
24
C_MODE_START
25
26
typedef
struct
st_wt_resource_id
WT_RESOURCE_ID;
27
typedef
struct
st_wt_resource
WT_RESOURCE
;
28
29
typedef
struct
st_wt_resource_type
{
30
my_bool (*compare)(
const
void
*a,
const
void
*b);
31
const
void
*(*make_key)(
const
WT_RESOURCE_ID *
id
, uint *len);
/* not used */
32
}
WT_RESOURCE_TYPE
;
33
34
struct
st_wt_resource_id
{
35
ulonglong value;
36
const
WT_RESOURCE_TYPE
*type;
37
};
38
/* the below differs from sizeof(WT_RESOURCE_ID) by the amount of padding */
39
#define sizeof_WT_RESOURCE_ID (sizeof(ulonglong)+sizeof(void*))
40
41
#define WT_WAIT_STATS 24
42
#define WT_CYCLE_STATS 32
43
extern
ulonglong
wt_wait_table
[WT_WAIT_STATS];
44
extern
uint32
wt_wait_stats
[WT_WAIT_STATS+1];
45
extern
uint32
wt_cycle_stats
[2][WT_CYCLE_STATS+1];
46
extern
uint32 wt_success_stats;
47
48
typedef
struct
st_wt_thd
{
49
/*
50
XXX
51
there's no protection (mutex) against concurrent access of the
52
dynarray below. it is assumed that a caller will have it anyway
53
(not to protect this array but to protect its own - caller's -
54
data structures), and we'll get it for free. A caller needs to
55
ensure that a blocker won't release a resource before a blocked
56
thread starts waiting, which is usually done with a mutex.
57
58
If the above assumption is wrong, we'll need to add a mutex here.
59
*/
60
DYNAMIC_ARRAY
my_resources;
61
/*
62
'waiting_for' is modified under waiting_for->lock, and only by thd itself
63
'waiting_for' is read lock-free (using pinning protocol), but a thd object
64
can read its own 'waiting_for' without any locks or tricks.
65
*/
66
WT_RESOURCE
*waiting_for;
67
LF_PINS
*pins;
68
69
/* pointers to values */
70
const
ulong *timeout_short;
71
const
ulong *deadlock_search_depth_short;
72
const
ulong *timeout_long;
73
const
ulong *deadlock_search_depth_long;
74
75
/*
76
weight relates to the desirability of a transaction being killed if it's
77
part of a deadlock. In a deadlock situation transactions with lower weights
78
are killed first.
79
80
Examples of using the weight to implement different selection strategies:
81
82
1. Latest
83
Keep all weights equal.
84
2. Random
85
Assight weights at random.
86
(variant: modify a weight randomly before every lock request)
87
3. Youngest
88
Set weight to -NOW()
89
4. Minimum locks
90
count locks granted in your lock manager, store the value as a weight
91
5. Minimum work
92
depends on the definition of "work". For example, store the number
93
of rows modifies in this transaction (or a length of REDO log for a
94
transaction) as a weight.
95
96
It is only statistically relevant and is not protected by any locks.
97
*/
98
ulong
volatile
weight;
99
/*
100
'killed' is indirectly protected by waiting_for->lock because
101
a killed thread needs to clear its 'waiting_for' and thus needs a lock.
102
That is a thread needs an exclusive lock to read 'killed' reliably.
103
But other threads may change 'killed' from 0 to 1, a shared
104
lock is enough for that.
105
*/
106
my_bool killed;
107
#ifndef DBUG_OFF
108
const
char
*name;
109
#endif
110
}
WT_THD
;
111
112
#define WT_TIMEOUT ETIMEDOUT
113
#define WT_OK 0
114
#define WT_DEADLOCK -1
115
#define WT_DEPTH_EXCEEDED -2
116
#define WT_FREE_TO_GO -3
117
118
void
wt_init(
void
);
119
void
wt_end(
void
);
120
void
wt_thd_lazy_init
(
WT_THD
*,
const
ulong *,
const
ulong *,
const
ulong *,
const
ulong *);
121
void
wt_thd_destroy(
WT_THD
*);
122
int
wt_thd_will_wait_for
(
WT_THD
*,
WT_THD
*,
const
WT_RESOURCE_ID *);
123
int
wt_thd_cond_timedwait
(
WT_THD
*,
mysql_mutex_t
*);
124
void
wt_thd_release
(
WT_THD
*,
const
WT_RESOURCE_ID *);
125
#define wt_thd_release_all(THD) wt_thd_release((THD), 0)
126
my_bool
wt_resource_id_memcmp
(
const
void
*,
const
void
*);
127
128
C_MODE_END
129
130
#endif
include
waiting_threads.h
Generated on Sat Nov 9 2013 01:24:46 for MySQL 5.6.14 Source Code Document by
1.8.1.2