LibreOffice Module store (master) 1
storbase.cxx
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#include "storbase.hxx"
21
22#include <sal/types.h>
23#include <rtl/alloc.h>
24#include <rtl/ref.hxx>
25#include <osl/diagnose.h>
26
27#include <store/types.h>
28#include "object.hxx"
29
30#include <stdio.h>
31
32using namespace store;
33
34// PageData::Allocator_Impl (default allocator).
35
36namespace store
37{
38
42{
43public:
47
50
51 storeError initialize (sal_uInt16 nPageSize);
52
53protected:
54 virtual ~Allocator_Impl() override;
55
56private:
57 rtl_cache_type * m_page_cache;
58 sal_uInt16 m_page_size;
59
62 virtual void allocate_Impl (void ** ppPage, sal_uInt16 * pnSize) override;
63 virtual void deallocate_Impl (void * pPage) override;
64};
65
66} // namespace store
67
68PageData::Allocator_Impl::Allocator_Impl()
69 : m_page_cache(nullptr), m_page_size(0)
70{}
71
74{
75 char name[RTL_CACHE_NAME_LENGTH + 1];
76 std::size_t size = sal::static_int_cast<std::size_t>(nPageSize);
77 (void) snprintf (name, sizeof(name), "store_page_alloc_%" SAL_PRI_SIZET "u", size);
78
79 m_page_cache = rtl_cache_create (name, size, 0, nullptr, nullptr, nullptr, nullptr, nullptr, 0);
80 if (!m_page_cache)
82
83 m_page_size = nPageSize;
84 return store_E_None;
85}
86
88{
89 rtl_cache_destroy(m_page_cache);
90 m_page_cache = nullptr;
91}
92
93void PageData::Allocator_Impl::allocate_Impl (void ** ppPage, sal_uInt16 * pnSize)
94{
95 OSL_PRECOND((ppPage != nullptr) && (pnSize != nullptr), "contract violation");
96 if ((ppPage != nullptr) && (pnSize != nullptr))
97 {
98 *ppPage = rtl_cache_alloc(m_page_cache);
99 *pnSize = m_page_size;
100 }
101}
102
104{
105 OSL_PRECOND(pPage != nullptr, "contract violation");
106 rtl_cache_free(m_page_cache, pPage);
107}
108
111{
113 if (!xAllocator.is())
114 return store_E_OutOfMemory;
115
116 rxAllocator = &*xAllocator;
117 return xAllocator->initialize (nPageSize);
118}
119
121{
122}
123
124/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~OStorePageObject()
Destruction.
Definition: storbase.cxx:120
Allocator_Impl & operator=(const Allocator_Impl &)=delete
Allocator_Impl()
Construction (two phase).
Definition: storbase.cxx:68
virtual ~Allocator_Impl() override
Definition: storbase.cxx:87
virtual void allocate_Impl(void **ppPage, sal_uInt16 *pnSize) override
PageData::Allocator implementation.
Definition: storbase.cxx:93
storeError initialize(sal_uInt16 nPageSize)
Definition: storbase.cxx:73
virtual void deallocate_Impl(void *pPage) override
Definition: storbase.cxx:103
Allocator_Impl(const Allocator_Impl &)=delete
rtl_cache_type * m_page_cache
Definition: storbase.cxx:57
static storeError createInstance(rtl::Reference< PageData::Allocator > &rxAllocator, sal_uInt16 nPageSize)
Definition: storbase.cxx:110
const char * name
Old OStorePageCache implementation.
Definition: lockbyte.cxx:133
sal_uInt16 size() const
size.
Definition: storbase.hxx:267
storeError
Error Code enumeration.
Definition: types.h:73
@ store_E_OutOfMemory
Definition: types.h:90
@ store_E_None
Definition: types.h:74
#define SAL_PRI_SIZET