MySQL  8.0.26
Source Code Documentation
thr_lock.h
Go to the documentation of this file.
1 /* Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 /* For use with thr_lock:s */
24 
25 /**
26  @file include/thr_lock.h
27 */
28 
29 #ifndef _thr_lock_h
30 #define _thr_lock_h
31 
32 #include <sys/types.h>
33 
34 #include "my_inttypes.h"
35 #include "my_list.h"
36 #include "my_thread_local.h"
37 #include "mysql/psi/mysql_cond.h"
38 #include "mysql/psi/mysql_mutex.h"
39 
41 
42 struct THR_LOCK;
43 
45 
46 /*
47  Important: if a new lock type is added, a matching lock description
48  must be added to sql_test.cc's lock_descriptions array.
49 */
51  TL_IGNORE = -1,
52  TL_UNLOCK, /* UNLOCK ANY LOCK */
53  /*
54  Parser only! At open_tables() becomes TL_READ or
55  TL_READ_NO_INSERT depending on the binary log format
56  (SBR/RBR) and on the table category (log table).
57  Used for tables that are read by statements which
58  modify tables.
59  */
61  TL_READ, /* Read lock */
63  /* High prior. than TL_WRITE. Allow concurrent insert */
65  /* READ, Don't allow concurrent insert */
67  /*
68  Write lock, but allow other threads to read / write.
69  Used by BDB tables in MySQL to mark that someone is
70  reading/writing to the table.
71  */
73  /*
74  parser only! Late bound low_priority_flag.
75  At open_tables() becomes thd->insert_lock_default.
76  */
78  /*
79  WRITE lock used by concurrent insert. Will allow
80  READ, if one could use concurrent insert on table.
81  */
83  /*
84  parser only! Late bound low_priority flag.
85  At open_tables() becomes thd->update_lock_default.
86  */
88  /* WRITE lock that has lower priority than TL_READ */
90  /* Normal WRITE lock */
92  /* Abort new lock request with an error */
94 };
95 
97 
101 };
102 
108 };
109 
110 extern ulong max_write_lock_count;
112 
113 /*
114  A description of the thread which owns the lock. The address
115  of an instance of this structure is used to uniquely identify the thread.
116 */
117 
121 };
122 
124  THR_LOCK_INFO *owner{nullptr};
125  THR_LOCK_DATA *next{nullptr}, **prev{nullptr};
126  THR_LOCK *lock{nullptr};
127  mysql_cond_t *cond{nullptr};
129  void *status_param{nullptr}; /* Param to status functions */
130  void *debug_print_param{nullptr};
131  struct PSI_table *m_psi{nullptr};
132 };
133 
134 struct st_lock_list {
135  THR_LOCK_DATA *data{nullptr}, **last{nullptr};
136 };
137 
138 struct THR_LOCK {
141  struct st_lock_list read_wait;
142  struct st_lock_list read;
143  struct st_lock_list write_wait;
144  struct st_lock_list write;
145  /* write_lock_count is incremented for write locks and reset on read locks */
148  void (*get_status)(void *, int){nullptr}; /* When one gets a lock */
149  void (*copy_status)(void *, void *){nullptr};
150  void (*update_status)(void *){nullptr}; /* Before release of write */
151  void (*restore_status)(void *){nullptr}; /* Before release of read */
152  bool (*check_status)(void *){nullptr};
153 };
154 
155 extern LIST *thr_lock_thread_list;
156 
158  mysql_cond_t *suspend);
162  void *status_param);
164  enum thr_lock_type lock_type,
165  ulong lock_wait_timeout);
168  THR_LOCK_INFO *owner,
169  ulong lock_wait_timeout);
173 void thr_print_locks(void); /* For debugging */
174 void thr_set_lock_wait_callback(void (*before_wait)(void),
175  void (*after_wait)(void));
176 #endif /* _thr_lock_h */
struct PSI_table PSI_table
Definition: psi_table_bits.h:106
Some integer typedefs for easier portability.
static my_thread_id thread_id
Definition: my_thr_init.cc:62
uint32 my_thread_id
Definition: my_thread_local.h:33
static int count
Definition: myisam_ftdump.cc:42
Log info(cout, "NOTE")
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:78
Instrumentation helpers for conditions.
Instrumentation helpers for mutexes.
Definition: my_list.h:35
Definition: thr_lock.h:98
thr_lock_type type
Definition: thr_lock.h:99
thr_locked_row_action action
Definition: thr_lock.h:100
Definition: thr_lock.h:123
mysql_cond_t * cond
Definition: thr_lock.h:127
struct PSI_table * m_psi
Definition: thr_lock.h:131
THR_LOCK_INFO * owner
Definition: thr_lock.h:124
void * debug_print_param
Definition: thr_lock.h:130
THR_LOCK_DATA * next
Definition: thr_lock.h:125
thr_lock_type type
Definition: thr_lock.h:128
void * status_param
Definition: thr_lock.h:129
THR_LOCK_DATA ** prev
Definition: thr_lock.h:125
Definition: thr_lock.h:118
mysql_cond_t * suspend
Definition: thr_lock.h:120
my_thread_id thread_id
Definition: thr_lock.h:119
Definition: thr_lock.h:138
ulong write_lock_count
Definition: thr_lock.h:146
struct st_lock_list read_wait
Definition: thr_lock.h:141
struct st_lock_list write_wait
Definition: thr_lock.h:143
LIST list
Definition: thr_lock.h:139
void(* restore_status)(void *)
Definition: thr_lock.h:151
void(* get_status)(void *, int)
Definition: thr_lock.h:148
bool(* check_status)(void *)
Definition: thr_lock.h:152
struct st_lock_list write
Definition: thr_lock.h:144
mysql_mutex_t mutex
Definition: thr_lock.h:140
uint read_no_write_count
Definition: thr_lock.h:147
void(* copy_status)(void *, void *)
Definition: thr_lock.h:149
void(* update_status)(void *)
Definition: thr_lock.h:150
struct st_lock_list read
Definition: thr_lock.h:142
An instrumented cond structure.
Definition: mysql_cond_bits.h:49
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
Definition: thr_lock.h:134
THR_LOCK_DATA * data
Definition: thr_lock.h:135
THR_LOCK_DATA ** last
Definition: thr_lock.h:135
void thr_lock_merge_status(THR_LOCK_DATA **data, uint count)
Ensure that all locks for a given table have the same status_param.
Definition: thr_lock.cc:948
void thr_set_lock_wait_callback(void(*before_wait)(void), void(*after_wait)(void))
Definition: thr_lock.cc:127
void thr_lock_init(THR_LOCK *lock)
Definition: thr_lock.cc:305
void thr_lock_info_init(THR_LOCK_INFO *info, my_thread_id thread_id, mysql_cond_t *suspend)
Definition: thr_lock.cc:329
ulong locks_immediate
Definition: thr_lock.cc:114
thr_lock_type
Definition: thr_lock.h:50
@ TL_WRITE
Definition: thr_lock.h:91
@ TL_WRITE_LOW_PRIORITY
Definition: thr_lock.h:89
@ TL_WRITE_ONLY
Definition: thr_lock.h:93
@ TL_READ_NO_INSERT
Definition: thr_lock.h:66
@ TL_WRITE_DEFAULT
Definition: thr_lock.h:87
@ TL_UNLOCK
Definition: thr_lock.h:52
@ TL_READ_HIGH_PRIORITY
Definition: thr_lock.h:64
@ TL_WRITE_CONCURRENT_DEFAULT
Definition: thr_lock.h:77
@ TL_READ
Definition: thr_lock.h:61
@ TL_WRITE_ALLOW_WRITE
Definition: thr_lock.h:72
@ TL_READ_WITH_SHARED_LOCKS
Definition: thr_lock.h:62
@ TL_IGNORE
Definition: thr_lock.h:51
@ TL_WRITE_CONCURRENT_INSERT
Definition: thr_lock.h:82
@ TL_READ_DEFAULT
Definition: thr_lock.h:60
enum thr_lock_type thr_upgraded_concurrent_insert_lock
Definition: thr_lock.cc:115
enum_thr_lock_result
Definition: thr_lock.h:103
@ THR_LOCK_DEADLOCK
Definition: thr_lock.h:107
@ THR_LOCK_ABORTED
Definition: thr_lock.h:105
@ THR_LOCK_WAIT_TIMEOUT
Definition: thr_lock.h:106
@ THR_LOCK_SUCCESS
Definition: thr_lock.h:104
thr_locked_row_action
Definition: thr_lock.h:96
@ THR_NOWAIT
Definition: thr_lock.h:96
@ THR_SKIP
Definition: thr_lock.h:96
@ THR_DEFAULT
Definition: thr_lock.h:96
@ THR_WAIT
Definition: thr_lock.h:96
enum enum_thr_lock_result thr_lock(THR_LOCK_DATA *data, THR_LOCK_INFO *owner, enum thr_lock_type lock_type, ulong lock_wait_timeout)
Definition: thr_lock.cc:475
void thr_print_locks(void)
Definition: thr_lock.cc:1071
void thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread)
Definition: thr_lock.cc:1015
void thr_unlock(THR_LOCK_DATA *data)
Definition: thr_lock.cc:732
enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data, uint count, THR_LOCK_INFO *owner, ulong lock_wait_timeout)
Definition: thr_lock.cc:896
ulong locks_waited
Definition: thr_lock.h:44
void thr_multi_unlock(THR_LOCK_DATA **data, uint count)
Definition: thr_lock.cc:986
LIST * thr_lock_thread_list
Definition: thr_lock.cc:121
void thr_lock_delete(THR_LOCK *lock)
Definition: thr_lock.cc:321
mysql_mutex_t THR_LOCK_lock
Definition: my_thr_init.cc:76
void thr_lock_data_init(THR_LOCK *lock, THR_LOCK_DATA *data, void *status_param)
Definition: thr_lock.cc:337
ulong max_write_lock_count
Definition: thr_lock.cc:122
unsigned int uint
Definition: uca-dump.cc:29