MySQL 8.0.39
Source Code Documentation
my_xp_mutex.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 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#ifndef MY_XP_MUTEX_INCLUDED
25#define MY_XP_MUTEX_INCLUDED
26
28
29/**
30 @class My_xp_mutex
31
32 Abstract class used to wrap mutex for various implementations.
33
34 A typical use case is:
35
36 @code{.cpp}
37
38 My_xp_mutex *mutex= new My_xp_mutex_impl();
39 mutex->init(mutex_PSI_key, NULL);
40
41 mutex->lock();
42 ...
43 mutex->unlock();
44
45 @endcode
46*/
48 public:
49 /**
50 Initialize mutex.
51
52 @param key mutex instrumentation key
53 @param attr mutex attributes reference
54 @return success status
55 */
56
57 virtual int init(PSI_mutex_key key, const native_mutexattr_t *attr) = 0;
58
59 /**
60 Destroy mutex.
61
62 @return success status
63 */
64
65 virtual int destroy() = 0;
66
67 /**
68 Lock mutex.
69
70 @return success status
71 */
72
73 virtual int lock() = 0;
74
75 /**
76 Trylock mutex.
77
78 @return success status
79 */
80
81 virtual int trylock() = 0;
82
83 /**
84 Unlock mutex.
85
86 @return success status
87 */
88
89 virtual int unlock() = 0;
90
91 /**
92 To get native mutex reference.
93
94 @return native mutex pointer
95 */
96
98
99 virtual ~My_xp_mutex() = default;
100};
101
102#ifndef XCOM_STANDALONE
104 public:
105 explicit My_xp_mutex_server();
106 ~My_xp_mutex_server() override;
107
108 int init(PSI_mutex_key key, const native_mutexattr_t *attr) override;
109 int destroy() override;
110 int lock() override;
111 int trylock() override;
112 int unlock() override;
114
115 protected:
117};
118#endif
119
120#ifndef XCOM_STANDALONE
122#endif
123{
124 public:
125 explicit My_xp_mutex_impl() = default;
126 ~My_xp_mutex_impl() override = default;
127};
128
130 public:
131 /**
132 Initialize mutex attributes object
133
134 @param attr mutex attributes reference
135 @return success status
136 */
137
138 static int attr_init(native_mutexattr_t *attr);
139
140 /**
141 Destroy mutex attributes object
142
143 @param attr mutex attributes reference
144 @return success status
145 */
146
147 static int attr_destroy(native_mutexattr_t *attr);
148};
149
150#endif // MY_XP_MUTEX_INCLUDED
Definition: my_xp_mutex.h:123
~My_xp_mutex_impl() override=default
My_xp_mutex_impl()=default
Definition: my_xp_mutex.h:103
int trylock() override
Trylock mutex.
Definition: my_xp_mutex.cc:45
int destroy() override
Destroy mutex.
Definition: my_xp_mutex.cc:41
int lock() override
Lock mutex.
Definition: my_xp_mutex.cc:43
int unlock() override
Unlock mutex.
Definition: my_xp_mutex.cc:47
My_xp_mutex_server()
Definition: my_xp_mutex.cc:27
mysql_mutex_t * get_native_mutex() override
To get native mutex reference.
Definition: my_xp_mutex.cc:32
int init(PSI_mutex_key key, const native_mutexattr_t *attr) override
Initialize mutex.
Definition: my_xp_mutex.cc:34
~My_xp_mutex_server() override
Definition: my_xp_mutex.cc:30
mysql_mutex_t * m_mutex
Definition: my_xp_mutex.h:116
Definition: my_xp_mutex.h:129
static int attr_destroy(native_mutexattr_t *attr)
Destroy mutex attributes object.
Definition: my_xp_mutex.cc:62
static int attr_init(native_mutexattr_t *attr)
Initialize mutex attributes object.
Definition: my_xp_mutex.cc:50
Abstract class used to wrap mutex for various implementations.
Definition: my_xp_mutex.h:47
virtual mysql_mutex_t * get_native_mutex()=0
To get native mutex reference.
virtual int destroy()=0
Destroy mutex.
virtual int unlock()=0
Unlock mutex.
virtual int init(PSI_mutex_key key, const native_mutexattr_t *attr)=0
Initialize mutex.
virtual int lock()=0
Lock mutex.
virtual ~My_xp_mutex()=default
virtual int trylock()=0
Trylock mutex.
unsigned int PSI_mutex_key
Instrumented mutex key.
Definition: psi_mutex_bits.h:52
Instrumentation helpers for mutexes.
required string key
Definition: replication_asynchronous_connection_failover.proto:60
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
pthread_mutexattr_t native_mutexattr_t
Definition: thr_mutex_bits.h:56