MySQL 8.0.31
Source Code Documentation
buf0block_hint.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2020, 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#ifndef buf0block_hint_h
27#define buf0block_hint_h
28#include "buf0types.h"
29
30namespace buf {
32 public:
33 /** Stores the pointer to the block, which is currently buffer-fixed.
34 @param[in] block a pointer to a buffer-fixed block to be stored */
35 void store(buf_block_t *block);
36
37 /** Clears currently stored pointer. */
38 void clear();
39
40 /** Executes given function with the block pointer which was previously stored
41 or with nullptr if the pointer is no longer valid, was cleared or not stored.
42 @param[in] f The function to be executed. It will be passed the pointer.
43 If you wish to use the block pointer subsequently, you need to
44 ensure you buffer-fix it before returning from f.
45 @return the return value of f
46 */
47 template <typename F>
48 auto run_with_hint(F &&f) {
50 /* m_block could be changed during f() call, so we use local variable to
51 remember which block we need to unfix */
52 buf_block_t *buffer_fixed_block = m_block;
53 auto res = f(buffer_fixed_block);
54 buffer_unfix_block_if_needed(buffer_fixed_block);
55 return res;
56 }
57
58 private:
59 /** The block pointer stored by store(). */
61 /** If m_block is non-null, the m_block->page.id at time it was stored. */
63
64 /** A helper function which checks if m_block is not a dangling pointer and
65 still points to block with page with m_page_id and if so, buffer-fixes it,
66 otherwise clear()s it */
68
69 /** A helper function which decrements block->buf_fix_count if it's non-null
70 @param[in] block A pointer to a block or nullptr */
71 static void buffer_unfix_block_if_needed(buf_block_t *block);
72};
73
74} // namespace buf
75#endif /* buf0hint_h*/
The database buffer pool global types for the directory.
Definition: buf0block_hint.h:31
void clear()
Clears currently stored pointer.
Definition: buf0block_hint.cc:37
void buffer_fix_block_if_still_valid()
A helper function which checks if m_block is not a dangling pointer and still points to block with pa...
Definition: buf0block_hint.cc:39
buf_block_t * m_block
The block pointer stored by store().
Definition: buf0block_hint.h:60
static void buffer_unfix_block_if_needed(buf_block_t *block)
A helper function which decrements block->buf_fix_count if it's non-null.
Definition: buf0block_hint.cc:85
page_id_t m_page_id
If m_block is non-null, the m_block->page.id at time it was stored.
Definition: buf0block_hint.h:62
auto run_with_hint(F &&f)
Executes given function with the block pointer which was previously stored or with nullptr if the poi...
Definition: buf0block_hint.h:48
void store(buf_block_t *block)
Stores the pointer to the block, which is currently buffer-fixed.
Definition: buf0block_hint.cc:31
Page identifier.
Definition: buf0types.h:206
Definition: buf0block_hint.cc:29
The buffer control block structure.
Definition: buf0buf.h:1664