MySQL 8.0.39
Source Code Documentation
ut0guarded.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2021, 2024, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/** @file include/ut0guarded.h
29The ut::Guarded template which protects access to another class with mutex. */
30
31#ifndef ut0guarded_h
32#define ut0guarded_h
33
34#ifndef UNIV_LIBRARY
35#include "ut0cpu_cache.h"
36#include "ut0mutex.h"
37#endif
38
39namespace ut {
40// TBD: should latch_id be specified at runtime?
41template <typename Inner, latch_id_t latch_id>
42class Guarded {
43#ifndef UNIV_LIBRARY
45#endif
46 Inner inner;
47
48 public:
49 template <typename F>
50 auto latch_and_execute(F &&f, const ut::Location &loc) {
51#ifndef UNIV_LIBRARY
52 IB_mutex_guard guard{&mutex, loc};
53#endif
54 return std::forward<F>(f)(inner);
55 }
56
57 const Inner &peek() const { return inner; }
58};
59} // namespace ut
60#endif /* ut0guarded_h */
Definition: ut0guarded.h:42
Inner inner
Definition: ut0guarded.h:46
auto latch_and_execute(F &&f, const ut::Location &loc)
Definition: ut0guarded.h:50
Cacheline_padded< IB_mutex > mutex
Definition: ut0guarded.h:44
const Inner & peek() const
Definition: ut0guarded.h:57
This file contains a set of libraries providing overloads for regular dynamic allocation routines whi...
Definition: aligned_alloc.h:48
Definition: ut0mutex.h:128
A utility wrapper class, which adds padding at the end of the wrapped structure, so that the next obj...
Definition: ut0cpu_cache.h:55
Definition: ut0core.h:33
Utilities related to CPU cache.
Policy based mutexes.