MySQL 9.1.0
Source Code Documentation
instrumented_mutex.h
Go to the documentation of this file.
1/* Copyright (c) 2023, 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 INSTRUMENTED_MUTEX_H
25#define INSTRUMENTED_MUTEX_H
26#include <mutex>
28
29namespace mysql {
30/**
31 mutex is a C++ STL mutex (std::mutex) implementation using the
32 instrumented MySQL mutex component API.
33
34 This allows for P_S instrumentation of mutexes in components.
35
36 Example usage:
37 @code
38 #include <mysql/components/library_mysys/instrumented_mutex.h>
39 namespace x {
40 ...
41 using mysql::mutex;
42 ...
43 mutex m(KEY_psi_mutex);
44 ...
45 std::unique_lock(m);
46 ...
47 };
48 @endcode
49*/
50
51class mutex {
52 public:
54 mysql_mutex_init(m_key, &m_mtx, nullptr);
55 }
56 mutex(const mutex &) = delete;
59 bool try_lock() { return 0 == mysql_mutex_trylock(&m_mtx); }
62
63 protected:
66};
67
68} // namespace mysql
69
70#endif // INSTRUMENTED_MUTEX_H
mutex is a C++ STL mutex (std::mutex) implementation using the instrumented MySQL mutex component API...
Definition: instrumented_mutex.h:51
void lock()
Definition: instrumented_mutex.h:58
mysql_mutex_t m_mtx
Definition: instrumented_mutex.h:64
void unlock()
Definition: instrumented_mutex.h:60
mutex(const mutex &)=delete
mutex(PSI_mutex_key key) noexcept
Definition: instrumented_mutex.h:53
bool try_lock()
Definition: instrumented_mutex.h:59
~mutex()
Definition: instrumented_mutex.h:57
mysql_mutex_t * native_handle()
Definition: instrumented_mutex.h:61
PSI_mutex_key m_key
Definition: instrumented_mutex.h:65
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:50
#define mysql_mutex_destroy(M)
Definition: mysql_mutex.h:46
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:57
#define mysql_mutex_trylock(M)
Definition: mysql_mutex.h:53
#define mysql_mutex_init(K, M, A)
Definition: mysql_mutex.h:41
unsigned int PSI_mutex_key
Instrumented mutex key.
Definition: psi_mutex_bits.h:52
Definition: instrumented_condition_variable.h:32
required string key
Definition: replication_asynchronous_connection_failover.proto:60
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50