LCOV - code coverage report
Current view: top level - store/source - storbase.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 36 38 94.7 %
Date: 2014-11-03 Functions: 11 14 78.6 %
Legend: Lines: hit not hit

          Line data    Source code
       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 "boost/noncopyable.hpp"
      23             : #include "sal/types.h"
      24             : #include "rtl/alloc.h"
      25             : #include "rtl/ref.hxx"
      26             : #include "osl/diagnose.h"
      27             : 
      28             : #include "store/types.h"
      29             : #include "object.hxx"
      30             : 
      31             : #include <stdio.h>
      32             : 
      33             : using namespace store;
      34             : 
      35             : /*========================================================================
      36             :  *
      37             :  * SharedCount::Allocator.
      38             :  *
      39             :  *======================================================================*/
      40             : SharedCount::Allocator &
      41       23310 : SharedCount::Allocator::get()
      42             : {
      43       23310 :     static Allocator g_aSharedCountAllocator;
      44       23310 :     return g_aSharedCountAllocator;
      45             : }
      46             : 
      47         292 : SharedCount::Allocator::Allocator()
      48             : {
      49             :     m_cache = rtl_cache_create (
      50             :         "store_shared_count_cache",
      51             :         sizeof(long),
      52             :         0, // objalign
      53             :         0, // constructor
      54             :         0, // destructor
      55             :         0, // reclaim
      56             :         0, // userarg
      57             :         0, // default source
      58             :         0  // flags
      59         292 :         );
      60         292 : }
      61             : 
      62         292 : SharedCount::Allocator::~Allocator()
      63             : {
      64         292 :     rtl_cache_destroy (m_cache), m_cache = 0;
      65         292 : }
      66             : 
      67             : /*========================================================================
      68             :  *
      69             :  * PageData::Allocator_Impl (default allocator).
      70             :  *
      71             :  *======================================================================*/
      72             : namespace store
      73             : {
      74             : 
      75             : class PageData::Allocator_Impl :
      76             :     public store::OStoreObject,
      77             :     public store::PageData::Allocator,
      78             :     private boost::noncopyable
      79             : {
      80             : public:
      81             :     /** Construction (two phase).
      82             :      */
      83             :     Allocator_Impl();
      84             : 
      85             :     storeError initialize (sal_uInt16 nPageSize);
      86             : 
      87             : protected:
      88             :     /** Destruction.
      89             :      */
      90             :     virtual ~Allocator_Impl();
      91             : 
      92             : private:
      93             :     /** Representation.
      94             :      */
      95             :     rtl_cache_type * m_page_cache;
      96             :     sal_uInt16       m_page_size;
      97             : 
      98             :     /** PageData::Allocator implementation.
      99             :      */
     100             :     virtual void allocate_Impl (void ** ppPage, sal_uInt16 * pnSize) SAL_OVERRIDE;
     101             :     virtual void deallocate_Impl (void * pPage) SAL_OVERRIDE;
     102             : };
     103             : 
     104             : } // namespace store
     105             : 
     106         296 : PageData::Allocator_Impl::Allocator_Impl()
     107         296 :     : m_page_cache(0), m_page_size(0)
     108         296 : {}
     109             : 
     110             : storeError
     111         296 : PageData::Allocator_Impl::initialize (sal_uInt16 nPageSize)
     112             : {
     113             :     char name[RTL_CACHE_NAME_LENGTH + 1];
     114         296 :     sal_Size size = sal::static_int_cast< sal_Size >(nPageSize);
     115         296 :     (void) snprintf (name, sizeof(name), "store_page_alloc_%" SAL_PRIuUINTPTR, size);
     116             : 
     117         296 :     m_page_cache = rtl_cache_create (name, size, 0, 0, 0, 0, 0, 0, 0);
     118         296 :     if (!m_page_cache)
     119           0 :         return store_E_OutOfMemory;
     120             : 
     121         296 :     m_page_size = nPageSize;
     122         296 :     return store_E_None;
     123             : }
     124             : 
     125         876 : PageData::Allocator_Impl::~Allocator_Impl()
     126             : {
     127         292 :     rtl_cache_destroy(m_page_cache), m_page_cache = 0;
     128         584 : }
     129             : 
     130        2748 : void PageData::Allocator_Impl::allocate_Impl (void ** ppPage, sal_uInt16 * pnSize)
     131             : {
     132             :     OSL_PRECOND((ppPage != 0) && (pnSize != 0), "contract violation");
     133        2748 :     if ((ppPage != 0) && (pnSize != 0))
     134        2748 :         *ppPage = rtl_cache_alloc(m_page_cache), *pnSize = m_page_size;
     135        2748 : }
     136             : 
     137        2714 : void PageData::Allocator_Impl::deallocate_Impl (void * pPage)
     138             : {
     139             :     OSL_PRECOND(pPage != 0, "contract violation");
     140        2714 :     rtl_cache_free(m_page_cache, pPage);
     141        2714 : }
     142             : 
     143             : /*========================================================================
     144             :  *
     145             :  * PageData::Allocator factory.
     146             :  *
     147             :  *======================================================================*/
     148             : 
     149             : storeError
     150         296 : PageData::Allocator::createInstance (rtl::Reference< PageData::Allocator > & rxAllocator, sal_uInt16 nPageSize)
     151             : {
     152         296 :     rtl::Reference< PageData::Allocator_Impl > xAllocator (new PageData::Allocator_Impl());
     153         296 :     if (!xAllocator.is())
     154           0 :         return store_E_OutOfMemory;
     155             : 
     156         296 :     rxAllocator = &*xAllocator;
     157         296 :     return xAllocator->initialize (nPageSize);
     158             : }
     159             : 
     160             : /*========================================================================
     161             :  *
     162             :  * OStorePageObject.
     163             :  *
     164             :  *======================================================================*/
     165             : /*
     166             :  * ~OStorePageObject.
     167             :  */
     168        9724 : OStorePageObject::~OStorePageObject (void)
     169             : {
     170        9724 : }
     171             : 
     172             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10