"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/jrd/TempSpace.cpp" between
Firebird-3.0.2.32703-0.tar.bz2 and Firebird-3.0.4.33054-0.tar.bz2

About: Firebird is a relational database offering many ANSI SQL standard features.

TempSpace.cpp  (Firebird-3.0.2.32703-0.tar.bz2):TempSpace.cpp  (Firebird-3.0.4.33054-0.tar.bz2)
skipping to change at line 42 skipping to change at line 42
#include "../common/os/path_utils.h" #include "../common/os/path_utils.h"
#include "../jrd/TempSpace.h" #include "../jrd/TempSpace.h"
using namespace Firebird; using namespace Firebird;
// Static definitions/initializations // Static definitions/initializations
const size_t MIN_TEMP_BLOCK_SIZE = 64 * 1024; const size_t MIN_TEMP_BLOCK_SIZE = 64 * 1024;
GlobalPtr<Mutex> TempSpace::initMutex; GlobalPtr<Mutex> TempSpace::globalMutex;
TempDirectoryList* TempSpace::tempDirs = NULL; TempDirectoryList* TempSpace::tempDirs = NULL;
FB_SIZE_T TempSpace::minBlockSize = 0; FB_SIZE_T TempSpace::minBlockSize = 0;
offset_t TempSpace::globalCacheUsage = 0; offset_t TempSpace::globalCacheUsage = 0;
// //
// In-memory block class // In-memory block class
// //
FB_SIZE_T TempSpace::MemoryBlock::read(offset_t offset, void* buffer, FB_SIZE_T length) FB_SIZE_T TempSpace::MemoryBlock::read(offset_t offset, void* buffer, FB_SIZE_T length)
{ {
skipping to change at line 110 skipping to change at line 110
TempSpace::TempSpace(MemoryPool& p, const PathName& prefix, bool dynamic) TempSpace::TempSpace(MemoryPool& p, const PathName& prefix, bool dynamic)
: pool(p), filePrefix(p, prefix), : pool(p), filePrefix(p, prefix),
logicalSize(0), physicalSize(0), localCacheUsage(0), logicalSize(0), physicalSize(0), localCacheUsage(0),
head(NULL), tail(NULL), tempFiles(p), head(NULL), tail(NULL), tempFiles(p),
initialBuffer(p), initiallyDynamic(dynamic), initialBuffer(p), initiallyDynamic(dynamic),
freeSegments(p) freeSegments(p)
{ {
if (!tempDirs) if (!tempDirs)
{ {
MutexLockGuard guard(initMutex, FB_FUNCTION); MutexLockGuard guard(globalMutex, FB_FUNCTION);
if (!tempDirs) if (!tempDirs)
{ {
MemoryPool& def_pool = *getDefaultMemoryPool(); MemoryPool& def_pool = *getDefaultMemoryPool();
tempDirs = FB_NEW_POOL(def_pool) TempDirectoryList(def_po ol); tempDirs = FB_NEW_POOL(def_pool) TempDirectoryList(def_po ol);
minBlockSize = Config::getTempBlockSize(); minBlockSize = Config::getTempBlockSize();
if (minBlockSize < MIN_TEMP_BLOCK_SIZE) if (minBlockSize < MIN_TEMP_BLOCK_SIZE)
minBlockSize = MIN_TEMP_BLOCK_SIZE; minBlockSize = MIN_TEMP_BLOCK_SIZE;
else else
minBlockSize = FB_ALIGN(minBlockSize, MIN_TEMP_BL OCK_SIZE); minBlockSize = FB_ALIGN(minBlockSize, MIN_TEMP_BL OCK_SIZE);
skipping to change at line 140 skipping to change at line 140
TempSpace::~TempSpace() TempSpace::~TempSpace()
{ {
while (head) while (head)
{ {
Block* temp = head->next; Block* temp = head->next;
delete head; delete head;
head = temp; head = temp;
} }
globalCacheUsage -= localCacheUsage; { // scope
MutexLockGuard guard(globalMutex, FB_FUNCTION);
globalCacheUsage -= localCacheUsage;
}
while (tempFiles.getCount()) while (tempFiles.getCount())
{
delete tempFiles.pop(); delete tempFiles.pop();
}
} }
// //
// TempSpace::read // TempSpace::read
// //
// Reads bytes from the temporary space // Reads bytes from the temporary space
// //
FB_SIZE_T TempSpace::read(offset_t offset, void* buffer, FB_SIZE_T length) FB_SIZE_T TempSpace::read(offset_t offset, void* buffer, FB_SIZE_T length)
{ {
skipping to change at line 278 skipping to change at line 279
physicalSize = size; physicalSize = size;
} }
else else
{ {
size = static_cast<FB_SIZE_T>(FB_ALIGN(logicalSize - phys icalSize, minBlockSize)); size = static_cast<FB_SIZE_T>(FB_ALIGN(logicalSize - phys icalSize, minBlockSize));
physicalSize += size; physicalSize += size;
} }
Block* block = NULL; Block* block = NULL;
if (globalCacheUsage + size <= size_t(Config::getTempCacheLimit() { // scope
)) MutexLockGuard guard(globalMutex, FB_FUNCTION);
{
try if (globalCacheUsage + size <= size_t(Config::getTempCach
{ eLimit()))
// allocate block in virtual memory
block = FB_NEW_POOL(pool) MemoryBlock(FB_NEW_POOL
(pool) UCHAR[size], tail, size);
localCacheUsage += size;
globalCacheUsage += size;
}
catch (const BadAlloc&)
{ {
// not enough memory try
{
// allocate block in virtual memory
block = FB_NEW_POOL(pool) MemoryBlock(FB_
NEW_POOL(pool) UCHAR[size], tail, size);
localCacheUsage += size;
globalCacheUsage += size;
}
catch (const BadAlloc&)
{
// not enough memory
}
} }
} }
// NS 2014-07-31: FIXME: missing exception handling. // NS 2014-07-31: FIXME: missing exception handling.
// error thrown in block of code below will leave TempSpace in in consistent state: // error thrown in block of code below will leave TempSpace in in consistent state:
// logical/physical size already increased while allocation has i n fact failed. // logical/physical size already increased while allocation has i n fact failed.
if (!block) if (!block)
{ {
// allocate block in the temp file // allocate block in the temp file
TempFile* const file = setupFile(size); TempFile* const file = setupFile(size);
 End of changes. 7 change blocks. 
18 lines changed or deleted 23 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)