1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: storbase.cxx,v $
7 * $Revision: 1.12.8.4 $
9 * last change: $Author: mhu $ $Date: 2008/10/31 18:28:18 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_store.hxx"
39 #include "storbase.hxx"
41 #include "sal/types.h"
42 #include "rtl/alloc.h"
43 #include "rtl/ref.hxx"
44 #include "osl/diagnose.h"
46 #include "store/types.h"
49 #ifndef INCLUDED_STDIO_H
51 #define INCLUDED_STDIO_H
54 using namespace store
;
56 /*========================================================================
58 * SharedCount::Allocator.
60 *======================================================================*/
61 SharedCount::Allocator
&
62 SharedCount::Allocator::get()
64 static Allocator g_aSharedCountAllocator
;
65 return g_aSharedCountAllocator
;
68 SharedCount::Allocator::Allocator()
70 m_cache
= rtl_cache_create (
71 "store_shared_count_cache",
83 SharedCount::Allocator::~Allocator()
85 rtl_cache_destroy (m_cache
), m_cache
= 0;
88 /*========================================================================
90 * PageData::Allocator_Impl (default allocator).
92 *======================================================================*/
96 class PageData::Allocator_Impl
:
97 public store::OStoreObject
,
98 public store::PageData::Allocator
101 /** Construction (two phase).
105 storeError
initialize (sal_uInt16 nPageSize
);
107 /** Delegate multiple inherited rtl::IReference.
109 virtual oslInterlockedCount SAL_CALL
acquire()
111 return OStoreObject::acquire();
113 virtual oslInterlockedCount SAL_CALL
release()
115 return OStoreObject::release();
121 virtual ~Allocator_Impl();
126 rtl_cache_type
* m_page_cache
;
127 sal_uInt16 m_page_size
;
129 /** PageData::Allocator implementation.
131 virtual void allocate_Impl (void ** ppPage
, sal_uInt16
* pnSize
);
132 virtual void deallocate_Impl (void * pPage
);
136 Allocator_Impl (Allocator_Impl
const &);
137 Allocator_Impl
& operator= (Allocator_Impl
const &);
142 PageData::Allocator_Impl::Allocator_Impl()
143 : m_page_cache(0), m_page_size(0)
147 PageData::Allocator_Impl::initialize (sal_uInt16 nPageSize
)
149 char name
[RTL_CACHE_NAME_LENGTH
+ 1];
150 sal_Size size
= sal::static_int_cast
< sal_Size
>(nPageSize
);
151 (void) snprintf (name
, sizeof(name
), "store_page_alloc_%lu", size
);
153 m_page_cache
= rtl_cache_create (name
, size
, 0, 0, 0, 0, 0, 0, 0);
155 return store_E_OutOfMemory
;
157 m_page_size
= nPageSize
;
161 PageData::Allocator_Impl::~Allocator_Impl()
163 rtl_cache_destroy(m_page_cache
), m_page_cache
= 0;
166 void PageData::Allocator_Impl::allocate_Impl (void ** ppPage
, sal_uInt16
* pnSize
)
168 OSL_PRECOND((ppPage
!= 0) && (pnSize
!= 0), "contract violation");
169 *ppPage
= rtl_cache_alloc(m_page_cache
), *pnSize
= m_page_size
;
172 void PageData::Allocator_Impl::deallocate_Impl (void * pPage
)
174 OSL_PRECOND(pPage
!= 0, "contract violation");
175 rtl_cache_free(m_page_cache
, pPage
);
178 /*========================================================================
180 * PageData::Allocator factory.
182 *======================================================================*/
185 PageData::Allocator::createInstance (rtl::Reference
< PageData::Allocator
> & rxAllocator
, sal_uInt16 nPageSize
)
187 rtl::Reference
< PageData::Allocator_Impl
> xAllocator (new PageData::Allocator_Impl());
188 if (!xAllocator
.is())
189 return store_E_OutOfMemory
;
191 rxAllocator
= &*xAllocator
;
192 return xAllocator
->initialize (nPageSize
);
195 /*========================================================================
199 *======================================================================*/
203 OStorePageObject::~OStorePageObject (void)