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