MySQL 26.7.0
Source Code Documentation
mutex_wrapper.h
Go to the documentation of this file.
1// Copyright (c) 2026, 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 MYSQL_CONCURRENCY_MUTEX_WRAPPER_H
25#define MYSQL_CONCURRENCY_MUTEX_WRAPPER_H
26
28
29namespace mysql::concurrency {
30
31/// @brief MySQL wrapper for a mutex, template which may be specialized with
32/// a specific implementation of a mutex, e.g. MySQL mutex, and satisfying
33/// the following requirements:
34/// - Lockable
35/// - Destructible
36/// - not copyable
37/// - not movable
39 public:
42
43 // Disable copy-move semantics
44 Mutex_wrapper(const Mutex_wrapper &) = delete;
46 Mutex_wrapper &operator=(const Mutex_wrapper &src) = delete;
48
49 /// @brief Acquire a lock, blocks access to a critical section until "unlock"
50 /// is called
51 void lock() noexcept;
52
53 /// Non-blocking try-lock operation
54 /// @retval true Lock has been acquired
55 /// @retval false Lock has NOT been acquired
56 bool try_lock() noexcept;
57
58 /// @brief Unblocks access to a critical section for other threads
59 void unlock();
60
61 /// @brief Returns the native handle of the mutex
62 /// @return Reference to the underlying mysql_mutex_t object
63 decltype(auto) native_handle() { return &m_mutex; }
64
65 protected:
67};
68
69} // namespace mysql::concurrency
70
71#endif // MYSQL_CONCURRENCY_MUTEX_WRAPPER_H
MySQL wrapper for a mutex, template which may be specialized with a specific implementation of a mute...
Definition: mutex_wrapper.h:38
bool try_lock() noexcept
Non-blocking try-lock operation.
Definition: mutex_wrapper.cpp:34
Mutex_wrapper(PSI_mutex_key key)
Definition: mutex_wrapper.cpp:28
Mutex_wrapper & operator=(Mutex_wrapper &&src)=delete
void unlock()
Unblocks access to a critical section for other threads.
Definition: mutex_wrapper.cpp:38
decltype(auto) native_handle()
Returns the native handle of the mutex.
Definition: mutex_wrapper.h:63
void lock() noexcept
Acquire a lock, blocks access to a critical section until "unlock" is called.
Definition: mutex_wrapper.cpp:32
Mutex_wrapper & operator=(const Mutex_wrapper &src)=delete
mysql_mutex_t m_mutex
Definition: mutex_wrapper.h:66
Mutex_wrapper(Mutex_wrapper &&)=delete
~Mutex_wrapper()
Definition: mutex_wrapper.cpp:40
Mutex_wrapper(const Mutex_wrapper &)=delete
unsigned int PSI_mutex_key
Instrumented mutex key.
Definition: psi_mutex_bits.h:52
Definition: cache_line_size.h:31
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
Instrumentation helpers for mutexes.
required string key
Definition: replication_asynchronous_connection_failover.proto:60
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50