From 207344786b91a140a1de3ba9248f7d00b5be8625 Mon Sep 17 00:00:00 2001 From: prabatuty Date: Wed, 13 Jul 2011 07:33:32 +0000 Subject: [PATCH] code reorg and doxygen documentation --- include/Allocator.h | 50 +++++++++++++++++++++++++++++------------------- src/storage/Database.cxx | 6 ++++-- src/storage/PageInfo.cxx | 17 +--------------- 3 files changed, 35 insertions(+), 38 deletions(-) diff --git a/include/Allocator.h b/include/Allocator.h index bf95519b..af6f9d38 100644 --- a/include/Allocator.h +++ b/include/Allocator.h @@ -20,7 +20,7 @@ #include #include -typedef void Page; +typedef void Page; enum AllocType { @@ -33,34 +33,44 @@ enum AllocType class VarSizeInfo { public: - InUse size_; - InUse isUsed_; + InUse size_; /**< size of the allocated node */ + InUse isUsed_; /**< bit to represent whether this node is under use */ }; - -//Each Page has this info. -//pages are of size PAGE_SIZE normally. -//If data size is more than PAGE_SIZE then -//contigous pages are merged and those pages wont -//have this info in them.Only the start page where that -//data is stored will have this info -//This object is stored at the start of each page #define HAS_SPACE 1 #define IS_DIRTY 2 +/** +* @brief Page Header Info +* +* Database is divided into equal size parts(PAGE_SIZE) called pages. Each page contains page header (PageInfo) to store information related to pages such as whether it is in use, next used page for chunk, etc +* +* If data size is more than PAGE_SIZE then contigous pages are merged and those pages wont have page header info(pageInfo) in them. Only the start page where that data is stored will have header information. This object is stored at the start of each page unless it is a merged page. +*/ + class PageInfo { public: - InUse isUsed_; - InUse flags; //stores hasFreeSpace and isDirty + InUse isUsed_; /**< specifies whether this page is in use */ + InUse flags; /**< stores hasFreeSpace and isDirty flags */ + + Page *nextPageAfterMerge_; /**firstPage_ = chunk->curPage_; PageInfo* firstPageInfo = ((PageInfo*)chunk->firstPage_); - firstPageInfo->setFirstPageAsUsed(); chunk->setChunkID(id); chunk->setAllocType(type); chunk->initMutex(id); @@ -506,7 +505,10 @@ DbRetVal Database::createSystemDatabaseChunk(AllocType type, size_t size, int id { int multiple = os::floor(chunk->allocSize_ / PAGE_SIZE); int offset = ((multiple + 1) * PAGE_SIZE); - firstPageInfo->nextPageAfterMerge_ = ((char*)firstPageInfo)+ offset; + firstPageInfo->setPageAsUsed(offset); + } + else { + firstPageInfo->setPageAsUsed(chunk->allocSize_); } if (0 == size) diff --git a/src/storage/PageInfo.cxx b/src/storage/PageInfo.cxx index fb1de22a..2a7c6689 100644 --- a/src/storage/PageInfo.cxx +++ b/src/storage/PageInfo.cxx @@ -37,7 +37,7 @@ void PageInfo::setPageAsUsed(size_t offset) if (ret != 0) printError(ErrSysFatal, "Fatal:CAS Failed"); InUse flagToSet=0; SETBIT(flagToSet, HAS_SPACE); - ret = Mutex::CASGen(&flags , flags, flagToSet);; + ret = Mutex::CASGen(&flags, flags, flagToSet);; if (ret != 0) printError(ErrSysFatal, "Fatal:CAS Failed"); ret = Mutex::CASL((long*)&nextPage_, (long)nextPage_, 0); if (ret != 0) printError(ErrSysFatal, "Fatal:CAS Failed"); @@ -53,18 +53,3 @@ void PageInfo::setPageAsUsed(size_t offset) return; } -void PageInfo::setFirstPageAsUsed() -{ - int ret = Mutex::CASGen(&isUsed_, 0,1); - if (ret != 0) printError(ErrSysFatal, "Fatal:CAS Failed"); - InUse flagToSet=0; - SETBIT(flagToSet, HAS_SPACE); - ret = Mutex::CASGen(&flags , flags, flagToSet);; - if (ret != 0) printError(ErrSysFatal, "Fatal:CAS Failed"); - ret = Mutex::CASL((long*)&nextPageAfterMerge_, (long)nextPageAfterMerge_, 0); - if (ret != 0) printError(ErrSysFatal, "Fatal:CAS Failed"); - //nextPage_ = NULL; - ret = Mutex::CASL((long*)&nextPage_, (long)nextPage_, 0); - if (ret != 0) printError(ErrSysFatal, "Fatal:CAS Failed"); - return; -} -- 2.11.4.GIT