MySQL  8.0.17
Source Code Documentation
thr_lock.h
Go to the documentation of this file.
1 /* Copyright (c) 2000, 2018, 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, 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 
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 {
145  /* write_lock_count is incremented for write locks and reset on read locks */
148  void (*get_status)(void *, int){0}; /* When one gets a lock */
149  void (*copy_status)(void *, void *){0};
150  void (*update_status)(void *){0}; /* Before release of write */
151  void (*restore_status)(void *){0}; /* Before release of read */
152  bool (*check_status)(void *){0};
153 };
154 
155 extern LIST *thr_lock_thread_list;
156 
158  mysql_cond_t *suspend);
159 void thr_lock_init(THR_LOCK *lock);
160 void thr_lock_delete(THR_LOCK *lock);
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 */
175  enum thr_lock_type new_lock_type);
176 void thr_set_lock_wait_callback(void (*before_wait)(void),
177  void (*after_wait)(void));
178 #endif /* _thr_lock_h */
Instrumentation helpers for mutexes.
Definition: thr_lock.h:123
THR_LOCK_DATA * data
Definition: thr_lock.h:135
Definition: thr_lock.h:66
void thr_lock_info_init(THR_LOCK_INFO *info, my_thread_id thread_id, mysql_cond_t *suspend)
Definition: thr_lock.cc:331
void * status_param
Definition: thr_lock.h:129
Definition: thr_lock.h:106
ssize_t count
Definition: memcached.c:386
An instrumented cond structure.
Definition: mysql_cond_bits.h:49
Definition: thr_lock.h:104
Definition: thr_lock.h:91
Some integer typedefs for easier portability.
#define bool
Definition: config_static.h:42
ulong max_write_lock_count
Definition: thr_lock.cc:121
bool(* check_status)(void *)
Definition: thr_lock.h:152
Definition: thr_lock.h:105
Definition: thr_lock.h:82
Definition: thr_lock.h:51
Definition: thr_lock.h:72
void thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread)
Definition: thr_lock.cc:1017
void thr_unlock(THR_LOCK_DATA *data)
Definition: thr_lock.cc:734
struct st_lock_list read
Definition: thr_lock.h:142
void thr_set_lock_wait_callback(void(*before_wait)(void), void(*after_wait)(void))
Definition: thr_lock.cc:126
Definition: thr_lock.h:138
void thr_multi_unlock(THR_LOCK_DATA **data, uint count)
Definition: thr_lock.cc:990
Definition: thr_lock.h:52
Definition: thr_lock.h:96
struct PSI_table * m_psi
Definition: thr_lock.h:131
mysql_mutex_t mutex
Definition: thr_lock.h:140
void thr_lock_data_init(THR_LOCK *lock, THR_LOCK_DATA *data, void *status_param)
Definition: thr_lock.cc:339
void(* restore_status)(void *)
Definition: thr_lock.h:151
Definition: thr_lock.h:93
enum thr_lock_type thr_upgraded_concurrent_insert_lock
Definition: thr_lock.cc:114
thr_lock_type type
Definition: thr_lock.h:128
ulong locks_immediate
Definition: thr_lock.cc:113
Definition: thr_lock.h:77
void thr_lock_delete(THR_LOCK *lock)
Definition: thr_lock.cc:322
thr_lock_type
Definition: thr_lock.h:50
void thr_print_locks(void)
Definition: thr_lock.cc:1121
THR_LOCK_INFO * owner
Definition: thr_lock.h:124
void * debug_print_param
Definition: thr_lock.h:130
Definition: thr_lock.h:134
Definition: thr_lock.h:98
void(* copy_status)(void *, void *)
Definition: thr_lock.h:149
struct st_lock_list write
Definition: thr_lock.h:144
unsigned int uint
Definition: uca-dump.cc:29
void thr_lock_init(THR_LOCK *lock)
Definition: thr_lock.cc:305
uint read_no_write_count
Definition: thr_lock.h:147
my_thread_id thread_id
Definition: thr_lock.h:119
struct st_lock_list read_wait
Definition: thr_lock.h:141
Definition: thr_lock.h:107
LIST * thr_lock_thread_list
Definition: thr_lock.cc:120
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:952
Definition: thr_lock.h:60
Instrumentation helpers for conditions.
void(* update_status)(void *)
Definition: thr_lock.h:150
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:477
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:900
mysql_cond_t * suspend
Definition: thr_lock.h:120
struct st_lock_list write_wait
Definition: thr_lock.h:143
Definition: thr_lock.h:64
uint32 my_thread_id
Definition: my_thread_local.h:33
ulong write_lock_count
Definition: thr_lock.h:146
THR_LOCK * lock
Definition: thr_lock.h:126
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
Definition: thr_lock.h:61
thr_lock_type type
Definition: thr_lock.h:99
Definition: thr_lock.h:96
Definition: my_list.h:41
THR_LOCK_DATA ** prev
Definition: thr_lock.h:125
Definition: thr_lock.h:87
Definition: thr_lock.h:62
void(* get_status)(void *, int)
Definition: thr_lock.h:148
thr_locked_row_action
Definition: thr_lock.h:96
THR_LOCK_DATA ** last
Definition: thr_lock.h:135
void thr_downgrade_write_lock(THR_LOCK_DATA *data, enum thr_lock_type new_lock_type)
Definition: thr_lock.cc:1083
thr_locked_row_action action
Definition: thr_lock.h:100
LIST list
Definition: thr_lock.h:139
ulong locks_waited
Definition: thr_lock.cc:113
Log info(cout, "NOTE")
struct PSI_table PSI_table
Definition: psi_table_bits.h:106
Definition: thr_lock.h:96
THR_LOCK_DATA * next
Definition: thr_lock.h:125
Definition: thr_lock.h:89
mysql_mutex_t THR_LOCK_lock
Definition: my_thr_init.cc:76
unsigned long ulong
Definition: my_inttypes.h:48
Definition: thr_lock.h:96
static my_thread_id thread_id
Definition: my_thr_init.cc:62
mysql_cond_t * cond
Definition: thr_lock.h:127
enum_thr_lock_result
Definition: thr_lock.h:103
Definition: thr_lock.h:118