LibreOffice Module store (master) 1
storcach.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#pragma once
21
22#include <sal/config.h>
23
24#include <memory>
25
26#include <sal/types.h>
27
28#include <store/types.h>
29#include "object.hxx"
30
31namespace rtl { template <class reference_type> class Reference; }
32namespace store { struct PageData; }
33
34namespace store
35{
36
37struct Entry;
38
39class PageCache :
41{
42 static size_t const theTableSize = 32;
43 static_assert((theTableSize & (theTableSize-1)) == 0, "table size should be a power of 2");
44
49 size_t const m_page_shift;
50
51 size_t m_hash_entries; // total number of entries in table.
52 size_t m_nHit;
53 size_t m_nMissed;
54
55 static int hash_Impl(sal_uInt32 a, size_t s, size_t q, size_t m)
56 {
57 return static_cast<int>(((a + (a >> s) + (a >> (s << 1))) >> q) & m);
58 }
59 int hash_index_Impl (sal_uInt32 nOffset)
60 {
61 return hash_Impl(nOffset, m_hash_shift, m_page_shift, m_hash_size - 1);
62 }
63
64 Entry * lookup_Impl (Entry * entry, sal_uInt32 nOffset);
65 void rescale_Impl (std::size_t new_size);
66
67public:
68 explicit PageCache (sal_uInt16 nPageSize);
69
70 PageCache(const PageCache&) = delete;
71 PageCache& operator=(const PageCache&) = delete;
72
74 std::shared_ptr<PageData> & rxPage,
75 sal_uInt32 nOffset);
76
78 std::shared_ptr<PageData> const & rxPage,
79 sal_uInt32 nOffset);
80
82 std::shared_ptr<PageData> const & rxPage,
83 sal_uInt32 nOffset);
84
86 sal_uInt32 nOffset);
87
88protected:
89 virtual ~PageCache() override;
90};
91
94 sal_uInt16 nPageSize
95);
96
97} // namespace store
98
99/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
size_t m_hash_shift
Definition: storcach.hxx:48
PageCache & operator=(const PageCache &)=delete
size_t m_hash_entries
Definition: storcach.hxx:51
virtual ~PageCache() override
Definition: storcach.cxx:180
int hash_index_Impl(sal_uInt32 nOffset)
Definition: storcach.hxx:59
storeError lookupPageAt(std::shared_ptr< PageData > &rxPage, sal_uInt32 nOffset)
Definition: storcach.cxx:277
storeError updatePageAt(std::shared_ptr< PageData > const &rxPage, sal_uInt32 nOffset)
Definition: storcach.cxx:332
static int hash_Impl(sal_uInt32 a, size_t s, size_t q, size_t m)
Definition: storcach.hxx:55
void rescale_Impl(std::size_t new_size)
Definition: storcach.cxx:211
size_t m_nMissed
Definition: storcach.hxx:53
static size_t const theTableSize
Definition: storcach.hxx:42
size_t m_hash_size
Definition: storcach.hxx:47
PageCache(sal_uInt16 nPageSize)
Definition: storcach.cxx:167
Entry * lookup_Impl(Entry *entry, sal_uInt32 nOffset)
Definition: storcach.cxx:255
Entry * m_hash_table_0[theTableSize]
Definition: storcach.hxx:46
PageCache(const PageCache &)=delete
Entry ** m_hash_table
Definition: storcach.hxx:43
storeError insertPageAt(std::shared_ptr< PageData > const &rxPage, sal_uInt32 nOffset)
Definition: storcach.cxx:300
storeError removePageAt(sal_uInt32 nOffset)
Definition: storcach.cxx:362
size_t const m_page_shift
Definition: storcach.hxx:49
uno_Any a
Reference
m
Old OStorePageCache implementation.
Definition: lockbyte.cxx:133
storeError PageCache_createInstance(rtl::Reference< store::PageCache > &rxCache, sal_uInt16 nPageSize)
Definition: storcach.cxx:401
storeError
Error Code enumeration.
Definition: types.h:73