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