00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "fennel/common/CommonPreamble.h"
00025 #include "fennel/segment/RandomAllocationSegmentBaseImpl.h"
00026 #include "fennel/segment/RandomAllocationSegmentImpl.h"
00027
00028 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/segment/RandomAllocationSegment.cpp#13 $");
00029
00030 RandomAllocationSegment::RandomAllocationSegment(
00031 SharedSegment delegateSegment)
00032 : RandomAllocationSegmentBase(delegateSegment)
00033 {
00034 nPagesPerExtent = (getUsablePageSize() - sizeof(ExtentAllocationNode))
00035 / sizeof(PageEntry);
00036
00037
00038 nPagesPerSegAlloc = nPagesPerExtent*nExtentsPerSegAlloc + 1;
00039 }
00040
00041 void RandomAllocationSegment::formatPageExtents(
00042 SegmentAllocationNode &segAllocNode,
00043 ExtentNum &extentNum)
00044 {
00045 formatPageExtentsTemplate<
00046 ExtentAllocationNode,
00047 ExtentAllocLock,
00048 PageEntry>(
00049 segAllocNode,
00050 extentNum);
00051 }
00052
00053 PageId RandomAllocationSegment::allocatePageId(PageOwnerId ownerId)
00054 {
00055 return allocatePageIdFromSegment(ownerId, getTracingSegment());
00056 }
00057
00058 PageId RandomAllocationSegment::getSegAllocPageIdForWrite(
00059 PageId origSegAllocPageId)
00060 {
00061 return origSegAllocPageId;
00062 }
00063
00064 void RandomAllocationSegment::undoSegAllocPageWrite(PageId segAllocPageId)
00065 {
00066 }
00067
00068 PageId RandomAllocationSegment::getExtAllocPageIdForWrite(ExtentNum extentNum)
00069 {
00070 return getExtentAllocPageId(extentNum);
00071 }
00072
00073 PageId RandomAllocationSegment::getSegAllocPageIdForRead(
00074 PageId origSegAllocPageId,
00075 SharedSegment &allocNodeSegment)
00076 {
00077 allocNodeSegment = getTracingSegment();
00078 return origSegAllocPageId;
00079 }
00080
00081 PageId RandomAllocationSegment::getExtAllocPageIdForRead(
00082 ExtentNum extentNum,
00083 SharedSegment &allocNodeSegment)
00084 {
00085 allocNodeSegment = getTracingSegment();
00086 return getExtentAllocPageId(extentNum);
00087 }
00088
00089 void RandomAllocationSegment::getPageEntryCopy(
00090 PageId pageId,
00091 PageEntry &pageEntryCopy,
00092 bool isAllocated,
00093 bool thisSegment)
00094 {
00095 getPageEntryCopyTemplate<ExtentAllocationNode, ExtentAllocLock, PageEntry>(
00096 pageId,
00097 pageEntryCopy,
00098 isAllocated,
00099 thisSegment);
00100 }
00101
00102 PageId RandomAllocationSegment::allocateFromNewExtent(
00103 ExtentNum extentNum,
00104 PageOwnerId ownerId)
00105 {
00106 return
00107 allocateFromNewExtentTemplate<
00108 ExtentAllocationNode,
00109 ExtentAllocLock,
00110 PageEntry>(
00111 extentNum,
00112 ownerId,
00113 getTracingSegment());
00114 }
00115
00116 PageId RandomAllocationSegment::allocateFromExtent(
00117 ExtentNum extentNum,
00118 PageOwnerId ownerId)
00119 {
00120 return
00121 allocateFromExtentTemplate<
00122 ExtentAllocationNode,
00123 ExtentAllocLock,
00124 PageEntry>(
00125 extentNum,
00126 ownerId,
00127 getTracingSegment());
00128 }
00129
00130 void RandomAllocationSegment::freePageEntry(
00131 ExtentNum extentNum,
00132 BlockNum iPageInExtent)
00133 {
00134 freePageEntryTemplate<
00135 ExtentAllocationNode,
00136 ExtentAllocLock,
00137 PageEntry>(
00138 extentNum,
00139 iPageInExtent);
00140 }
00141
00142 PageId RandomAllocationSegment::getPageSuccessor(PageId pageId)
00143 {
00144 PageEntry pageEntry;
00145
00146 getPageEntryCopy(pageId, pageEntry, true, true);
00147 return pageEntry.successorId;
00148 }
00149
00150 void RandomAllocationSegment::setPageSuccessor(
00151 PageId pageId,
00152 PageId successorId)
00153 {
00154 setPageSuccessorTemplate<ExtentAllocationNode, ExtentAllocLock>(
00155 pageId,
00156 successorId,
00157 getTracingSegment());
00158 }
00159
00160 PageOwnerId RandomAllocationSegment::getPageOwnerId(
00161 PageId pageId,
00162 bool thisSegment)
00163 {
00164 return getPageOwnerIdTemplate<PageEntry>(pageId, thisSegment);
00165 }
00166
00167 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/segment/RandomAllocationSegment.cpp#13 $");
00168
00169