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