LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/store/source - storbase.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 40 42 95.2 %
Date: 2013-07-09 Functions: 13 14 92.9 %
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             : 
      21             : #include "storbase.hxx"
      22             : 
      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     3143046 : SharedCount::Allocator::get()
      42             : {
      43     3143046 :     static Allocator g_aSharedCountAllocator;
      44     3143046 :     return g_aSharedCountAllocator;
      45             : }
      46             : 
      47         300 : 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         300 :         );
      60         300 : }
      61             : 
      62         300 : SharedCount::Allocator::~Allocator()
      63             : {
      64         300 :     rtl_cache_destroy (m_cache), m_cache = 0;
      65         300 : }
      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             : {
      79             : public:
      80             :     /** Construction (two phase).
      81             :      */
      82             :     Allocator_Impl();
      83             : 
      84             :     storeError initialize (sal_uInt16 nPageSize);
      85             : 
      86             :     /** Delegate multiple inherited rtl::IReference.
      87             :      */
      88     5033865 :     virtual oslInterlockedCount SAL_CALL acquire()
      89             :     {
      90     5033865 :         return OStoreObject::acquire();
      91             :     }
      92     5033865 :     virtual oslInterlockedCount SAL_CALL release()
      93             :     {
      94     5033865 :         return OStoreObject::release();
      95             :     }
      96             : 
      97             : protected:
      98             :     /** Destruction.
      99             :      */
     100             :     virtual ~Allocator_Impl();
     101             : 
     102             : private:
     103             :     /** Representation.
     104             :      */
     105             :     rtl_cache_type * m_page_cache;
     106             :     sal_uInt16       m_page_size;
     107             : 
     108             :     /** PageData::Allocator implementation.
     109             :      */
     110             :     virtual void allocate_Impl (void ** ppPage, sal_uInt16 * pnSize);
     111             :     virtual void deallocate_Impl (void * pPage);
     112             : 
     113             :     /** Not implemented.
     114             :      */
     115             :     Allocator_Impl (Allocator_Impl const &);
     116             :     Allocator_Impl & operator= (Allocator_Impl const &);
     117             : };
     118             : 
     119             : } // namespace store
     120             : 
     121        5440 : PageData::Allocator_Impl::Allocator_Impl()
     122        5440 :     : m_page_cache(0), m_page_size(0)
     123        5440 : {}
     124             : 
     125             : storeError
     126        5440 : PageData::Allocator_Impl::initialize (sal_uInt16 nPageSize)
     127             : {
     128             :     char name[RTL_CACHE_NAME_LENGTH + 1];
     129        5440 :     sal_Size size = sal::static_int_cast< sal_Size >(nPageSize);
     130        5440 :     (void) snprintf (name, sizeof(name), "store_page_alloc_%" SAL_PRIuUINTPTR, size);
     131             : 
     132        5440 :     m_page_cache = rtl_cache_create (name, size, 0, 0, 0, 0, 0, 0, 0);
     133        5440 :     if (!m_page_cache)
     134           0 :         return store_E_OutOfMemory;
     135             : 
     136        5440 :     m_page_size = nPageSize;
     137        5440 :     return store_E_None;
     138             : }
     139             : 
     140       16320 : PageData::Allocator_Impl::~Allocator_Impl()
     141             : {
     142        5440 :     rtl_cache_destroy(m_page_cache), m_page_cache = 0;
     143       10880 : }
     144             : 
     145       98917 : void PageData::Allocator_Impl::allocate_Impl (void ** ppPage, sal_uInt16 * pnSize)
     146             : {
     147             :     OSL_PRECOND((ppPage != 0) && (pnSize != 0), "contract violation");
     148       98917 :     if ((ppPage != 0) && (pnSize != 0))
     149       98917 :         *ppPage = rtl_cache_alloc(m_page_cache), *pnSize = m_page_size;
     150       98917 : }
     151             : 
     152       98917 : void PageData::Allocator_Impl::deallocate_Impl (void * pPage)
     153             : {
     154             :     OSL_PRECOND(pPage != 0, "contract violation");
     155       98917 :     rtl_cache_free(m_page_cache, pPage);
     156       98917 : }
     157             : 
     158             : /*========================================================================
     159             :  *
     160             :  * PageData::Allocator factory.
     161             :  *
     162             :  *======================================================================*/
     163             : 
     164             : storeError
     165        5440 : PageData::Allocator::createInstance (rtl::Reference< PageData::Allocator > & rxAllocator, sal_uInt16 nPageSize)
     166             : {
     167        5440 :     rtl::Reference< PageData::Allocator_Impl > xAllocator (new PageData::Allocator_Impl());
     168        5440 :     if (!xAllocator.is())
     169           0 :         return store_E_OutOfMemory;
     170             : 
     171        5440 :     rxAllocator = &*xAllocator;
     172        5440 :     return xAllocator->initialize (nPageSize);
     173             : }
     174             : 
     175             : /*========================================================================
     176             :  *
     177             :  * OStorePageObject.
     178             :  *
     179             :  *======================================================================*/
     180             : /*
     181             :  * ~OStorePageObject.
     182             :  */
     183     1461534 : OStorePageObject::~OStorePageObject (void)
     184             : {
     185     1461534 : }
     186             : 
     187             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10