View | Details | Raw Unified | Return to issue 120629
Collapse All | Expand All

(-)sot/source/sdstor/stgcache.cxx (-73 / +49 lines)
Lines 44-49 Link Here
44
#include "stgdir.hxx"
44
#include "stgdir.hxx"
45
#include "stgio.hxx"
45
#include "stgio.hxx"
46
46
47
#include "precompiled_sot.hxx"
48
#include <algorithm>
49
47
/*************************************************************************/
50
/*************************************************************************/
48
//-----------------------------------------------------------------------------
51
//-----------------------------------------------------------------------------
49
typedef std::hash_map
52
typedef std::hash_map
Lines 73-82 Link Here
73
    bDirty = sal_False;
76
    bDirty = sal_False;
74
    nPage  = 0;
77
    nPage  = 0;
75
    pData  = new sal_uInt8[ nData ];
78
    pData  = new sal_uInt8[ nData ];
76
    pNext1 =
77
    pNext2 =
78
    pLast1 =
79
    pLast2 = NULL;
80
	pOwner = NULL;
79
	pOwner = NULL;
81
}
80
}
82
81
Lines 113-119 Link Here
113
{
112
{
114
	nRef = 0;
113
	nRef = 0;
115
	pStrm = NULL;
114
	pStrm = NULL;
116
	pCur = pElem1 = NULL;
117
    nPageSize = 512;
115
    nPageSize = 512;
118
    nError = SVSTREAM_OK;
116
    nError = SVSTREAM_OK;
119
	bMyStream = sal_False;
117
	bMyStream = sal_False;
Lines 151-191 Link Here
151
    pElem->nPage = nPg;
149
    pElem->nPage = nPg;
152
    // For data security, clear the buffer contents
150
    // For data security, clear the buffer contents
153
    memset( pElem->pData, 0, pElem->nData );
151
    memset( pElem->pData, 0, pElem->nData );
154
152
    if( !pLRUCache )
155
	// insert to LRU
153
	pLRUCache = new UsrStgPagePtr_Impl();
156
    if( pCur )
154
    (*(UsrStgPagePtr_Impl*)pLRUCache)[pElem->nPage] = pElem;
157
    {
158
        pElem->pNext1 = pCur;
159
        pElem->pLast1 = pCur->pLast1;
160
        pElem->pNext1->pLast1 =
161
        pElem->pLast1->pNext1 = pElem;
162
    }
163
    else
164
        pElem->pNext1 = pElem->pLast1 = pElem;
165
	if( !pLRUCache )
166
		pLRUCache = new UsrStgPagePtr_Impl();
167
	(*(UsrStgPagePtr_Impl*)pLRUCache)[pElem->nPage] = pElem;
168
    pCur = pElem;
169
170
	// insert to Sorted
171
    if( !pElem1 )
172
        pElem1 = pElem->pNext2 = pElem->pLast2 = pElem;
173
    else
174
    {
175
        StgPage* p = pElem1;
176
        do
177
        {
178
            if( pElem->nPage < p->nPage )
179
                break;
180
            p = p->pNext2;
181
        } while( p != pElem1 );
182
        pElem->pNext2 = p;
183
        pElem->pLast2 = p->pLast2;
184
        pElem->pNext2->pLast2 =
185
        pElem->pLast2->pNext2 = pElem;
186
        if( p->nPage < pElem1->nPage )
187
            pElem1 = pElem;
188
    }
189
    return pElem;
155
    return pElem;
190
}
156
}
191
157
Lines 196-214 Link Here
196
    OSL_ENSURE( pElem, "The pointer should not be NULL!" );
162
    OSL_ENSURE( pElem, "The pointer should not be NULL!" );
197
    if ( pElem )
163
    if ( pElem )
198
    {
164
    {
199
        OSL_ENSURE( pElem->pNext1 && pElem->pLast1, "The pointers may not be NULL!" );
165
    //    OSL_ENSURE( pElem->pNext1 && pElem->pLast1, "The pointers may not be NULL!" );
200
        //remove from LRU
166
        //remove from LRU
201
        pElem->pNext1->pLast1 = pElem->pLast1;
202
        pElem->pLast1->pNext1 = pElem->pNext1;
203
        if( pCur == pElem )
204
            pCur = ( pElem->pNext1 == pElem ) ? NULL : pElem->pNext1;
205
        if( pLRUCache )
167
        if( pLRUCache )
206
            ((UsrStgPagePtr_Impl*)pLRUCache)->erase( pElem->nPage );
168
            ((UsrStgPagePtr_Impl*)pLRUCache)->erase( pElem->nPage );
207
        // remove from Sorted
208
        pElem->pNext2->pLast2 = pElem->pLast2;
209
        pElem->pLast2->pNext2 = pElem->pNext2;
210
        if( pElem1 == pElem )
211
            pElem1 = ( pElem->pNext2 == pElem ) ? NULL : pElem->pNext2;
212
        delete pElem;
169
        delete pElem;
213
    }
170
    }
214
}
171
}
Lines 217-232 Link Here
217
174
218
void StgCache::Clear()
175
void StgCache::Clear()
219
{
176
{
220
	StgPage* pElem = pCur;
177
    if( UsrStgPagePtr_Impl* pLRUCache = (UsrStgPagePtr_Impl*)this->pLRUCache )
221
	if( pCur ) do
178
        for( UsrStgPagePtr_Impl::iterator i = pLRUCache->begin(); i!=pLRUCache->end(); i++ )
222
	{
179
            delete i->second;
223
		StgPage* pDelete = pElem;
180
224
		pElem = pElem->pNext1;
225
		delete pDelete;
226
	}
227
    while( pCur != pElem );
228
    pCur = NULL;
229
	pElem1 = NULL;
230
	delete (UsrStgPagePtr_Impl*)pLRUCache;
181
	delete (UsrStgPagePtr_Impl*)pLRUCache;
231
	pLRUCache = NULL;
182
	pLRUCache = NULL;
232
}
183
}
Lines 243-261 Link Here
243
		// page found
194
		// page found
244
	    StgPage* pFound = (*aIt).second;
195
	    StgPage* pFound = (*aIt).second;
245
        OSL_ENSURE( pFound, "The pointer may not be NULL!" );
196
        OSL_ENSURE( pFound, "The pointer may not be NULL!" );
246
247
		if( pFound != pCur )
248
		{
249
            OSL_ENSURE( pFound->pNext1 && pFound->pLast1, "The pointers may not be NULL!" );
250
			// remove from LRU
251
			pFound->pNext1->pLast1 = pFound->pLast1;
252
			pFound->pLast1->pNext1 = pFound->pNext1;
253
			// insert to LRU
254
			pFound->pNext1 = pCur;
255
			pFound->pLast1 = pCur->pLast1;
256
			pFound->pNext1->pLast1 =
257
			pFound->pLast1->pNext1 = pFound;
258
		}
259
		return pFound;
197
		return pFound;
260
	}
198
	}
261
    return NULL;
199
    return NULL;
Lines 306-311 Link Here
306
244
307
sal_Bool StgCache::Commit( StgDirEntry* )
245
sal_Bool StgCache::Commit( StgDirEntry* )
308
{
246
{
247
#if 1
248
    const bool bCommittedMustOrdered = true;
249
250
    if( UsrStgPagePtr_Impl* pLRUCache = (UsrStgPagePtr_Impl*)this->pLRUCache )
251
        if( bCommittedMustOrdered )
252
        {
253
            std::vector< std::pair< sal_uInt32, StgPage * > > vPages( pLRUCache->size() );
254
            std::copy( pLRUCache->begin(), pLRUCache->end(), vPages.begin() );
255
            std::sort( vPages.begin(), vPages.end() );
256
257
            for( std::vector< std::pair< sal_uInt32, StgPage * > >::iterator i = vPages.begin(); i!=vPages.end(); i++ )
258
                if( i->second && i->second->bDirty )
259
                {
260
                    sal_Bool b = Write( i->second->nPage, i->second->pData, 1 );
261
                    if( !b )
262
                        return sal_False;
263
                    i->second->bDirty = sal_False;
264
                }
265
        }
266
        else
267
        {
268
            for( UsrStgPagePtr_Impl::iterator i = pLRUCache->begin(); i!=pLRUCache->end(); i++ )
269
                if( i->second && i->second->bDirty )
270
                {
271
                    sal_Bool b = Write( i->second->nPage, i->second->pData, 1 );
272
                    if( !b )
273
                        return sal_False;
274
                    i->second->bDirty = sal_False;
275
                }
276
        }
277
278
    pStrm->Flush();
279
    SetError( pStrm->GetError() );
280
281
#elif 1
309
    StgPage* p = pElem1;
282
    StgPage* p = pElem1;
310
    if( p ) do
283
    if( p ) do
311
    {
284
    {
Lines 348-353 Link Here
348
	    p = p->pNext1;
321
	    p = p->pNext1;
349
	} while( p != pElem1 );
322
	} while( p != pElem1 );
350
#endif
323
#endif
324
#endif
351
	return sal_True;
325
	return sal_True;
352
}
326
}
353
327
Lines 559-561 Link Here
559
    return ( ( nPos + nPageSize - 1 ) / nPageSize ) * nPageSize - 1;
533
    return ( ( nPos + nPageSize - 1 ) / nPageSize ) * nPageSize - 1;
560
}
534
}
561
535
536
const sal_uInt16 nMemPoolStgPage = (0x1000 - 64) / ( sizeof ( StgPage ) );
537
IMPL_FIXEDMEMPOOL_NEWDEL( StgPage,	 nMemPoolStgPage, nMemPoolStgPage )
(-)sot/source/sdstor/stgcache.hxx (-4 / +2 lines)
Lines 32-37 Link Here
32
#include <tools/stream.hxx>
32
#include <tools/stream.hxx>
33
#endif
33
#endif
34
#include <stgelem.hxx>
34
#include <stgelem.hxx>
35
#include "tools/mempool.hxx"
35
36
36
class UCBStorageStream;
37
class UCBStorageStream;
37
38
Lines 41-48 Link Here
41
class StorageBase;
42
class StorageBase;
42
43
43
class StgCache {
44
class StgCache {
44
	StgPage* pCur;							// top of LRU list
45
	StgPage* pElem1;						// top of ordered list
46
	sal_uLong nError;							// error code
45
	sal_uLong nError;							// error code
47
	sal_Int32 nPages;							// size of data area in pages
46
	sal_Int32 nPages;							// size of data area in pages
48
	sal_uInt16 nRef;							// reference count
47
	sal_uInt16 nRef;							// reference count
Lines 94-101 Link Here
94
class StgPage {
93
class StgPage {
95
	friend class StgCache;
94
	friend class StgCache;
96
	StgCache* pCache;						// the cache
95
	StgCache* pCache;						// the cache
97
	StgPage *pNext1, *pLast1;				// LRU chain
98
	StgPage *pNext2, *pLast2;				// ordered chain
99
	StgDirEntry* pOwner;					// owner
96
	StgDirEntry* pOwner;					// owner
100
	sal_Int32	nPage;							// page #
97
	sal_Int32	nPage;							// page #
101
	sal_uInt8*	pData;							// nPageSize characters
98
	sal_uInt8*	pData;							// nPageSize characters
Lines 123-128 Link Here
123
#endif
120
#endif
124
	}
121
	}
125
	void  SetPage( short, sal_Int32 );		// put an element
122
	void  SetPage( short, sal_Int32 );		// put an element
123
    DECL_FIXEDMEMPOOL_NEWDEL( StgPage );
126
};
124
};
127
125
128
#endif
126
#endif

Return to issue 120629