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