1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/store/UPAGE/UP_PAGE.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,165 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "UP_STD.H"
1.20 +
1.21 +#define UNUSED_VAR(a) a = a
1.22 +
1.23 +const TInt KMemPoolGranularity=16;
1.24 +
1.25 +EXPORT_C void MPagePool::PushL()
1.26 +/** Pushes this object onto the cleanup stack. */
1.27 + {
1.28 + CleanupStack::PushL(TCleanupItem(REINTERPRET_CAST(TCleanupOperation,AcquireL()),this));
1.29 + // platform dependency
1.30 + }
1.31 +
1.32 +EXPORT_C void MPagePool::Delete(TPageRef aRef)
1.33 +/** Deletes a page, ignoring any errors.
1.34 +
1.35 +@param aRef Reference to the page to delete */
1.36 + {
1.37 + TRAPD(ignore,DeleteL(aRef));
1.38 + UNUSED_VAR(ignore);
1.39 + }
1.40 +
1.41 +EXPORT_C void MPagePool::DeleteL(TPageRef aRef)
1.42 +/** Deletes a page, leaving if an error occurs.
1.43 +
1.44 +@param aRef Reference to the page to delete */
1.45 + {
1.46 + if (aRef!=KNullPageRef)
1.47 + DoDeleteL(aRef);
1.48 + }
1.49 +
1.50 +EXPORT_C CMemPagePool* CMemPagePool::NewL()
1.51 +/** Allocates and constructs a new CMemPagePool object.
1.52 +
1.53 +@return New CMemPagePool object */
1.54 + {
1.55 + CMemPagePool* pool=new(ELeave) CMemPagePool;
1.56 + return pool;
1.57 + }
1.58 +
1.59 +EXPORT_C CMemPagePool *CMemPagePool::NewLC()
1.60 +/** Allocates and constructs a new CMemPagePool object, and leaves it on the cleanup
1.61 +stack.
1.62 +
1.63 +@return New CMemPagePool object */
1.64 + {
1.65 + CMemPagePool* pool=NewL();
1.66 + CleanupStack::PushL(pool);
1.67 + return pool;
1.68 + }
1.69 +
1.70 +EXPORT_C CMemPagePool::CMemPagePool()
1.71 + : iPages(KMemPoolGranularity)
1.72 +/** Default constructor. */
1.73 + {}
1.74 +
1.75 +EXPORT_C CMemPagePool::~CMemPagePool()
1.76 +/** Destructor.
1.77 +
1.78 +On destruction, memory for all pages is freed. */
1.79 + {
1.80 + for (TInt ii=iPages.Count();--ii>=0;)
1.81 + User::Free(iPages[ii]);
1.82 + }
1.83 +
1.84 +EXPORT_C TPageAbandonFunction CMemPagePool::AcquireL()
1.85 +/** For memory-based pools, there is no need to abandon pages, so the function
1.86 +returned does nothing.
1.87 +
1.88 +@return Function that does nothing. */
1.89 + {
1.90 + return &DoAbandon;
1.91 + }
1.92 +
1.93 +EXPORT_C TAny* CMemPagePool::AllocL()
1.94 +/** Allocates a new unassigned page.
1.95 +
1.96 +@return Newly allocated page. */
1.97 + {
1.98 + TAny* page=User::AllocLC(KPoolPageSize);
1.99 + iPages.AppendL(page);
1.100 + CleanupStack::Pop();
1.101 + return page;
1.102 + }
1.103 +
1.104 +EXPORT_C TAny* CMemPagePool::LockL(TPageRef aRef)
1.105 +/** Returns a pointer to a specified page.
1.106 +
1.107 +@param aRef Reference to the page to get
1.108 +@return Page specified by aRef */
1.109 + {
1.110 + TAny* page=PageL(aRef);
1.111 + if (page==NULL)
1.112 + __LEAVE(KErrNotFound);
1.113 +//
1.114 + return page;
1.115 + }
1.116 +
1.117 +EXPORT_C TPageRef CMemPagePool::AssignL(const TAny* __DEBUG(aPage),TPageReclamation)
1.118 +//
1.119 +// Assign a reference to a newly allocated page. Supports only a single unassigned page at a time.
1.120 +//
1.121 + {
1.122 + __ASSERT_DEBUG(iPages[iPages.Count()-1]==aPage,User::Invariant());
1.123 + return TPageRef(iPages.Count());
1.124 + }
1.125 +
1.126 +EXPORT_C void CMemPagePool::UpdateL(const TAny*)
1.127 +//
1.128 +// Memory-based pages don't need to be updated.
1.129 +//
1.130 + {}
1.131 +
1.132 +EXPORT_C void CMemPagePool::Unlock(const TAny*,TPageChange)
1.133 +//
1.134 +// Memory-based pages don't need to be unlocked.
1.135 +//
1.136 + {}
1.137 +
1.138 +EXPORT_C void CMemPagePool::DoDeleteL(TPageRef aRef)
1.139 +//
1.140 +// Delete the page denoted by aRef.
1.141 +//
1.142 + {
1.143 + TAny*& page=PageL(aRef);
1.144 + if (page==NULL)
1.145 + __LEAVE(KErrNotFound);
1.146 +//
1.147 + User::Free(page);
1.148 + page=NULL;
1.149 + }
1.150 +
1.151 +TAny*& CMemPagePool::PageL(TPageRef aRef)
1.152 +//
1.153 +// Return the page slot at aRef.
1.154 +//
1.155 + {
1.156 + TInt i=aRef.Value()-1;
1.157 + if (i<0||i>=iPages.Count())
1.158 + __LEAVE(KErrNotFound);
1.159 +//
1.160 + return iPages[i];
1.161 + }
1.162 +
1.163 +void CMemPagePool::DoAbandon(MPagePool&)
1.164 +//
1.165 +// Abandoning memory-based pages is a no-op.
1.166 +//
1.167 + {}
1.168 +