mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-05-01 02:31:23 -07:00
Converting cbs to use node as the base type of its blocks.
Copied from Perforce Change: 190491 ServerID: perforce.ravenbrook.com
This commit is contained in:
parent
52658dc850
commit
eefe51f766
4 changed files with 108 additions and 139 deletions
226
mps/code/cbs.c
226
mps/code/cbs.c
|
|
@ -13,6 +13,7 @@
|
|||
*/
|
||||
|
||||
#include "cbs.h"
|
||||
#include "node.h"
|
||||
#include "range.h"
|
||||
#include "splay.h"
|
||||
#include "meter.h"
|
||||
|
|
@ -22,30 +23,22 @@
|
|||
SRCID(cbs, "$Id$");
|
||||
|
||||
|
||||
#define CBSBlockRange(block) (&(block)->rangeStruct)
|
||||
#define CBSBlockBase(block) RangeBase(CBSBlockRange(block))
|
||||
#define CBSBlockLimit(block) RangeLimit(CBSBlockRange(block))
|
||||
#define CBSBlockSetBase(block, addr) RangeSetBase(CBSBlockRange(block), addr)
|
||||
#define CBSBlockSetLimit(block, addr) RangeSetLimit(CBSBlockRange(block), addr)
|
||||
#define CBSBlockSize(block) RangeSize(CBSBlockRange(block))
|
||||
|
||||
|
||||
#define cbsOfLand(land) PARENT(CBSStruct, landStruct, land)
|
||||
#define cbsSplay(cbs) (&((cbs)->splayTreeStruct))
|
||||
#define cbsOfSplay(_splay) PARENT(CBSStruct, splayTreeStruct, _splay)
|
||||
#define cbsBlockTree(block) (&((block)->treeStruct))
|
||||
#define cbsBlockOfTree(_tree) TREE_ELT(CBSBlock, treeStruct, _tree)
|
||||
#define cbsFastBlockOfTree(_tree) \
|
||||
PARENT(CBSFastBlockStruct, cbsBlockStruct, cbsBlockOfTree(_tree))
|
||||
PARENT(CBSFastBlockStruct, nodeStruct, NodeOfTree(_tree))
|
||||
#define cbsFastBlockNode(_block) (&(_block)->nodeStruct)
|
||||
#define cbsZonedBlockOfTree(_tree) \
|
||||
PARENT(CBSZonedBlockStruct, cbsFastBlockStruct, cbsFastBlockOfTree(_tree))
|
||||
#define cbsZonedBlockNode(_block) cbsFastBlockNode(&(_block)->cbsFastBlockStruct)
|
||||
#define cbsBlockPool(cbs) RVALUE((cbs)->blockPool)
|
||||
|
||||
/* We pass the block base directly as a TreeKey (void *) assuming that
|
||||
Addr can be encoded, and possibly breaking <design/type/#addr.use>.
|
||||
On an exotic platform where this isn't true, pass the address of base.
|
||||
i.e. add an & */
|
||||
#define cbsBlockKey(block) ((TreeKey)CBSBlockBase(block))
|
||||
#define cbsBlockKey(block) ((TreeKey)NodeBase(block))
|
||||
#define keyOfBaseVar(baseVar) ((TreeKey)(baseVar))
|
||||
#define baseOfKey(key) ((Addr)(key))
|
||||
|
||||
|
|
@ -70,23 +63,6 @@ Bool CBSCheck(CBS cbs)
|
|||
}
|
||||
|
||||
|
||||
ATTRIBUTE_UNUSED
|
||||
static Bool CBSBlockCheck(CBSBlock block)
|
||||
{
|
||||
UNUSED(block); /* Required because there is no signature */
|
||||
CHECKL(block != NULL);
|
||||
|
||||
/* Can't use CHECKD_NOSIG because TreeEMPTY is NULL. */
|
||||
CHECKL(TreeCheck(cbsBlockTree(block)));
|
||||
|
||||
/* If the block is in the middle of being deleted, the range might be empty. */
|
||||
CHECKD_NOSIG(Range, &block->rangeStruct);
|
||||
|
||||
/* Can't check maxSize because it may be invalid at the time */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* cbsCompare -- Compare key to [base,limit)
|
||||
*
|
||||
* See <design/splay/#type.splay.compare.method>
|
||||
|
|
@ -95,16 +71,16 @@ static Bool CBSBlockCheck(CBSBlock block)
|
|||
static Compare cbsCompare(Tree tree, TreeKey key)
|
||||
{
|
||||
Addr base1, base2, limit2;
|
||||
CBSBlock block;
|
||||
Node block;
|
||||
|
||||
AVERT_CRITICAL(Tree, tree);
|
||||
AVER_CRITICAL(tree != TreeEMPTY);
|
||||
AVER_CRITICAL(key != NULL);
|
||||
|
||||
base1 = baseOfKey(key);
|
||||
block = cbsBlockOfTree(tree);
|
||||
base2 = CBSBlockBase(block);
|
||||
limit2 = CBSBlockLimit(block);
|
||||
block = NodeOfTree(tree);
|
||||
base2 = NodeBase(block);
|
||||
limit2 = NodeLimit(block);
|
||||
|
||||
if (base1 < base2)
|
||||
return CompareLESS;
|
||||
|
|
@ -116,7 +92,7 @@ static Compare cbsCompare(Tree tree, TreeKey key)
|
|||
|
||||
static TreeKey cbsKey(Tree tree)
|
||||
{
|
||||
return cbsBlockKey(cbsBlockOfTree(tree));
|
||||
return cbsBlockKey(NodeOfTree(tree));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -124,7 +100,7 @@ static TreeKey cbsKey(Tree tree)
|
|||
|
||||
static Bool cbsTestNode(SplayTree splay, Tree tree, void *closure)
|
||||
{
|
||||
CBSBlock block;
|
||||
Node block;
|
||||
Size *sizeP = closure;
|
||||
|
||||
AVERT(SplayTree, splay);
|
||||
|
|
@ -133,9 +109,9 @@ static Bool cbsTestNode(SplayTree splay, Tree tree, void *closure)
|
|||
AVER(*sizeP > 0);
|
||||
AVER(IsLandSubclass(CBSLand(cbsOfSplay(splay)), CBSFastLandClass));
|
||||
|
||||
block = cbsBlockOfTree(tree);
|
||||
block = NodeOfTree(tree);
|
||||
|
||||
return CBSBlockSize(block) >= *sizeP;
|
||||
return NodeSize(block) >= *sizeP;
|
||||
}
|
||||
|
||||
static Bool cbsTestTree(SplayTree splay, Tree tree,
|
||||
|
|
@ -166,7 +142,7 @@ static void cbsUpdateFastNode(SplayTree splay, Tree tree)
|
|||
AVERT_CRITICAL(Tree, tree);
|
||||
AVER_CRITICAL(IsLandSubclass(CBSLand(cbsOfSplay(splay)), CBSFastLandClass));
|
||||
|
||||
maxSize = CBSBlockSize(cbsBlockOfTree(tree));
|
||||
maxSize = NodeSize(NodeOfTree(tree));
|
||||
|
||||
if (TreeHasLeft(tree)) {
|
||||
Size size = cbsFastBlockOfTree(TreeLeft(tree))->maxSize;
|
||||
|
|
@ -190,7 +166,7 @@ static void cbsUpdateZonedNode(SplayTree splay, Tree tree)
|
|||
{
|
||||
ZoneSet zones;
|
||||
CBSZonedBlock zonedBlock;
|
||||
CBSBlock block;
|
||||
Node block;
|
||||
Arena arena;
|
||||
|
||||
AVERT_CRITICAL(SplayTree, splay);
|
||||
|
|
@ -200,9 +176,9 @@ static void cbsUpdateZonedNode(SplayTree splay, Tree tree)
|
|||
cbsUpdateFastNode(splay, tree);
|
||||
|
||||
zonedBlock = cbsZonedBlockOfTree(tree);
|
||||
block = &zonedBlock->cbsFastBlockStruct.cbsBlockStruct;
|
||||
block = cbsZonedBlockNode(zonedBlock);
|
||||
arena = LandArena(CBSLand(cbsOfSplay(splay)));
|
||||
zones = ZoneSetOfRange(arena, CBSBlockBase(block), CBSBlockLimit(block));
|
||||
zones = ZoneSetOfRange(arena, NodeBase(block), NodeLimit(block));
|
||||
|
||||
if (TreeHasLeft(tree))
|
||||
zones = ZoneSetUnion(zones, cbsZonedBlockOfTree(TreeLeft(tree))->zones);
|
||||
|
|
@ -270,7 +246,7 @@ static Res cbsInitComm(Land land, ArgList args, SplayUpdateNodeFunction update,
|
|||
static Res cbsInit(Land land, ArgList args)
|
||||
{
|
||||
return cbsInitComm(land, args, SplayTrivUpdate,
|
||||
sizeof(CBSBlockStruct));
|
||||
sizeof(NodeStruct));
|
||||
}
|
||||
|
||||
static Res cbsInitFast(Land land, ArgList args)
|
||||
|
|
@ -327,19 +303,19 @@ static Size cbsSize(Land land)
|
|||
|
||||
/* cbsBlockDestroy -- destroy a block */
|
||||
|
||||
static void cbsBlockDestroy(CBS cbs, CBSBlock block)
|
||||
static void cbsBlockDestroy(CBS cbs, Node block)
|
||||
{
|
||||
Size size;
|
||||
|
||||
AVERT(CBS, cbs);
|
||||
AVERT(CBSBlock, block);
|
||||
size = CBSBlockSize(block);
|
||||
AVERT(Node, block);
|
||||
size = NodeSize(block);
|
||||
|
||||
STATISTIC(--cbs->treeSize);
|
||||
AVER(cbs->size >= size);
|
||||
cbs->size -= size;
|
||||
|
||||
RangeFinish(CBSBlockRange(block));
|
||||
RangeFinish(NodeRange(block));
|
||||
PoolFree(cbsBlockPool(cbs), (Addr)block, cbs->blockStructSize);
|
||||
}
|
||||
|
||||
|
|
@ -351,55 +327,55 @@ static void cbsBlockDestroy(CBS cbs, CBSBlock block)
|
|||
* enabled.
|
||||
*/
|
||||
|
||||
static void cbsBlockDelete(CBS cbs, CBSBlock block)
|
||||
static void cbsBlockDelete(CBS cbs, Node block)
|
||||
{
|
||||
Bool b;
|
||||
|
||||
AVERT(CBS, cbs);
|
||||
AVERT(CBSBlock, block);
|
||||
AVERT(Node, block);
|
||||
|
||||
METER_ACC(cbs->treeSearch, cbs->treeSize);
|
||||
b = SplayTreeDelete(cbsSplay(cbs), cbsBlockTree(block));
|
||||
b = SplayTreeDelete(cbsSplay(cbs), NodeTree(block));
|
||||
AVER(b); /* expect block to be in the tree */
|
||||
cbsBlockDestroy(cbs, block);
|
||||
}
|
||||
|
||||
static void cbsBlockShrunk(CBS cbs, CBSBlock block, Size oldSize)
|
||||
static void cbsBlockShrunk(CBS cbs, Node block, Size oldSize)
|
||||
{
|
||||
Size newSize;
|
||||
|
||||
AVERT(CBS, cbs);
|
||||
AVERT(CBSBlock, block);
|
||||
AVERT(Node, block);
|
||||
|
||||
newSize = CBSBlockSize(block);
|
||||
newSize = NodeSize(block);
|
||||
AVER(oldSize > newSize);
|
||||
AVER(cbs->size >= oldSize - newSize);
|
||||
|
||||
SplayNodeRefresh(cbsSplay(cbs), cbsBlockTree(block));
|
||||
SplayNodeRefresh(cbsSplay(cbs), NodeTree(block));
|
||||
cbs->size -= oldSize - newSize;
|
||||
}
|
||||
|
||||
static void cbsBlockGrew(CBS cbs, CBSBlock block, Size oldSize)
|
||||
static void cbsBlockGrew(CBS cbs, Node block, Size oldSize)
|
||||
{
|
||||
Size newSize;
|
||||
|
||||
AVERT(CBS, cbs);
|
||||
AVERT(CBSBlock, block);
|
||||
AVERT(Node, block);
|
||||
|
||||
newSize = CBSBlockSize(block);
|
||||
newSize = NodeSize(block);
|
||||
AVER(oldSize < newSize);
|
||||
|
||||
SplayNodeRefresh(cbsSplay(cbs), cbsBlockTree(block));
|
||||
SplayNodeRefresh(cbsSplay(cbs), NodeTree(block));
|
||||
cbs->size += newSize - oldSize;
|
||||
}
|
||||
|
||||
/* cbsBlockAlloc -- allocate a new block and set its base and limit,
|
||||
but do not insert it into the tree yet */
|
||||
|
||||
static Res cbsBlockAlloc(CBSBlock *blockReturn, CBS cbs, Range range)
|
||||
static Res cbsBlockAlloc(Node *blockReturn, CBS cbs, Range range)
|
||||
{
|
||||
Res res;
|
||||
CBSBlock block;
|
||||
Node block;
|
||||
Addr p;
|
||||
|
||||
AVER(blockReturn != NULL);
|
||||
|
|
@ -409,14 +385,14 @@ static Res cbsBlockAlloc(CBSBlock *blockReturn, CBS cbs, Range range)
|
|||
res = PoolAlloc(&p, cbsBlockPool(cbs), cbs->blockStructSize);
|
||||
if (res != ResOK)
|
||||
goto failPoolAlloc;
|
||||
block = (CBSBlock)p;
|
||||
block = (Node)p;
|
||||
|
||||
TreeInit(cbsBlockTree(block));
|
||||
RangeCopy(CBSBlockRange(block), range);
|
||||
TreeInit(NodeTree(block));
|
||||
RangeCopy(NodeRange(block), range);
|
||||
|
||||
SplayNodeInit(cbsSplay(cbs), cbsBlockTree(block));
|
||||
SplayNodeInit(cbsSplay(cbs), NodeTree(block));
|
||||
|
||||
AVERT(CBSBlock, block);
|
||||
AVERT(Node, block);
|
||||
*blockReturn = block;
|
||||
return ResOK;
|
||||
|
||||
|
|
@ -427,18 +403,18 @@ failPoolAlloc:
|
|||
|
||||
/* cbsBlockInsert -- insert a block into the tree */
|
||||
|
||||
static void cbsBlockInsert(CBS cbs, CBSBlock block)
|
||||
static void cbsBlockInsert(CBS cbs, Node block)
|
||||
{
|
||||
Bool b;
|
||||
|
||||
AVERT(CBS, cbs);
|
||||
AVERT(CBSBlock, block);
|
||||
AVERT(Node, block);
|
||||
|
||||
METER_ACC(cbs->treeSearch, cbs->treeSize);
|
||||
b = SplayTreeInsert(cbsSplay(cbs), cbsBlockTree(block));
|
||||
b = SplayTreeInsert(cbsSplay(cbs), NodeTree(block));
|
||||
AVER(b);
|
||||
STATISTIC(++cbs->treeSize);
|
||||
cbs->size += CBSBlockSize(block);
|
||||
cbs->size += NodeSize(block);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -457,7 +433,7 @@ static Res cbsInsert(Range rangeReturn, Land land, Range range)
|
|||
Res res;
|
||||
Addr base, limit, newBase, newLimit;
|
||||
Tree leftSplay, rightSplay;
|
||||
CBSBlock leftBlock, rightBlock;
|
||||
Node leftBlock, rightBlock;
|
||||
Bool leftMerge, rightMerge;
|
||||
Size oldSize;
|
||||
|
||||
|
|
@ -492,46 +468,46 @@ static Res cbsInsert(Range rangeReturn, Land land, Range range)
|
|||
leftBlock = NULL;
|
||||
leftMerge = FALSE;
|
||||
} else {
|
||||
leftBlock = cbsBlockOfTree(leftSplay);
|
||||
AVER(CBSBlockLimit(leftBlock) <= base);
|
||||
leftMerge = CBSBlockLimit(leftBlock) == base;
|
||||
leftBlock = NodeOfTree(leftSplay);
|
||||
AVER(NodeLimit(leftBlock) <= base);
|
||||
leftMerge = NodeLimit(leftBlock) == base;
|
||||
}
|
||||
|
||||
if (rightSplay == TreeEMPTY) {
|
||||
rightBlock = NULL;
|
||||
rightMerge = FALSE;
|
||||
} else {
|
||||
rightBlock = cbsBlockOfTree(rightSplay);
|
||||
if (rightBlock != NULL && limit > CBSBlockLimit(rightBlock)) {
|
||||
rightBlock = NodeOfTree(rightSplay);
|
||||
if (rightBlock != NULL && limit > NodeLimit(rightBlock)) {
|
||||
/* .insert.overlap */
|
||||
res = ResFAIL;
|
||||
goto fail;
|
||||
}
|
||||
rightMerge = CBSBlockBase(rightBlock) == limit;
|
||||
rightMerge = NodeBase(rightBlock) == limit;
|
||||
}
|
||||
|
||||
newBase = leftMerge ? CBSBlockBase(leftBlock) : base;
|
||||
newLimit = rightMerge ? CBSBlockLimit(rightBlock) : limit;
|
||||
newBase = leftMerge ? NodeBase(leftBlock) : base;
|
||||
newLimit = rightMerge ? NodeLimit(rightBlock) : limit;
|
||||
|
||||
if (leftMerge && rightMerge) {
|
||||
Size oldLeftSize = CBSBlockSize(leftBlock);
|
||||
Addr rightLimit = CBSBlockLimit(rightBlock);
|
||||
Size oldLeftSize = NodeSize(leftBlock);
|
||||
Addr rightLimit = NodeLimit(rightBlock);
|
||||
cbsBlockDelete(cbs, rightBlock);
|
||||
CBSBlockSetLimit(leftBlock, rightLimit);
|
||||
NodeSetLimit(leftBlock, rightLimit);
|
||||
cbsBlockGrew(cbs, leftBlock, oldLeftSize);
|
||||
|
||||
} else if (leftMerge) {
|
||||
oldSize = CBSBlockSize(leftBlock);
|
||||
CBSBlockSetLimit(leftBlock, limit);
|
||||
oldSize = NodeSize(leftBlock);
|
||||
NodeSetLimit(leftBlock, limit);
|
||||
cbsBlockGrew(cbs, leftBlock, oldSize);
|
||||
|
||||
} else if (rightMerge) {
|
||||
oldSize = CBSBlockSize(rightBlock);
|
||||
CBSBlockSetBase(rightBlock, base);
|
||||
oldSize = NodeSize(rightBlock);
|
||||
NodeSetBase(rightBlock, base);
|
||||
cbsBlockGrew(cbs, rightBlock, oldSize);
|
||||
|
||||
} else {
|
||||
CBSBlock block;
|
||||
Node block;
|
||||
res = cbsBlockAlloc(&block, cbs, range);
|
||||
if (res != ResOK)
|
||||
goto fail;
|
||||
|
|
@ -562,7 +538,7 @@ static Res cbsDelete(Range rangeReturn, Land land, Range range)
|
|||
{
|
||||
CBS cbs;
|
||||
Res res;
|
||||
CBSBlock block;
|
||||
Node block;
|
||||
Tree tree;
|
||||
Addr base, limit, oldBase, oldLimit;
|
||||
Size oldSize;
|
||||
|
|
@ -581,16 +557,16 @@ static Res cbsDelete(Range rangeReturn, Land land, Range range)
|
|||
res = ResFAIL;
|
||||
goto failSplayTreeSearch;
|
||||
}
|
||||
block = cbsBlockOfTree(tree);
|
||||
block = NodeOfTree(tree);
|
||||
|
||||
if (limit > CBSBlockLimit(block)) {
|
||||
if (limit > NodeLimit(block)) {
|
||||
res = ResFAIL;
|
||||
goto failLimitCheck;
|
||||
}
|
||||
|
||||
oldBase = CBSBlockBase(block);
|
||||
oldLimit = CBSBlockLimit(block);
|
||||
oldSize = CBSBlockSize(block);
|
||||
oldBase = NodeBase(block);
|
||||
oldLimit = NodeLimit(block);
|
||||
oldSize = NodeSize(block);
|
||||
RangeInit(rangeReturn, oldBase, oldLimit);
|
||||
|
||||
if (base == oldBase && limit == oldLimit) {
|
||||
|
|
@ -600,20 +576,20 @@ static Res cbsDelete(Range rangeReturn, Land land, Range range)
|
|||
} else if (base == oldBase) {
|
||||
/* remaining fragment at right */
|
||||
AVER(limit < oldLimit);
|
||||
CBSBlockSetBase(block, limit);
|
||||
NodeSetBase(block, limit);
|
||||
cbsBlockShrunk(cbs, block, oldSize);
|
||||
|
||||
} else if (limit == oldLimit) {
|
||||
/* remaining fragment at left */
|
||||
AVER(base > oldBase);
|
||||
CBSBlockSetLimit(block, base);
|
||||
NodeSetLimit(block, base);
|
||||
cbsBlockShrunk(cbs, block, oldSize);
|
||||
|
||||
} else {
|
||||
/* two remaining fragments. shrink block to represent fragment at
|
||||
left, and create new block for fragment at right. */
|
||||
RangeStruct newRange;
|
||||
CBSBlock newBlock;
|
||||
Node newBlock;
|
||||
AVER(base > oldBase);
|
||||
AVER(limit < oldLimit);
|
||||
RangeInit(&newRange, limit, oldLimit);
|
||||
|
|
@ -621,7 +597,7 @@ static Res cbsDelete(Range rangeReturn, Land land, Range range)
|
|||
if (res != ResOK) {
|
||||
goto failAlloc;
|
||||
}
|
||||
CBSBlockSetLimit(block, base);
|
||||
NodeSetLimit(block, base);
|
||||
cbsBlockShrunk(cbs, block, oldSize);
|
||||
cbsBlockInsert(cbs, newBlock);
|
||||
}
|
||||
|
|
@ -636,7 +612,7 @@ failSplayTreeSearch:
|
|||
}
|
||||
|
||||
|
||||
static Res cbsBlockDescribe(CBSBlock block, mps_lib_FILE *stream)
|
||||
static Res cbsBlockDescribe(Node block, mps_lib_FILE *stream)
|
||||
{
|
||||
Res res;
|
||||
|
||||
|
|
@ -645,8 +621,8 @@ static Res cbsBlockDescribe(CBSBlock block, mps_lib_FILE *stream)
|
|||
|
||||
res = WriteF(stream, 0,
|
||||
"[$P,$P)",
|
||||
(WriteFP)CBSBlockBase(block),
|
||||
(WriteFP)CBSBlockLimit(block),
|
||||
(WriteFP)NodeBase(block),
|
||||
(WriteFP)NodeLimit(block),
|
||||
NULL);
|
||||
return res;
|
||||
}
|
||||
|
|
@ -660,7 +636,7 @@ static Res cbsSplayNodeDescribe(Tree tree, mps_lib_FILE *stream)
|
|||
if (stream == NULL)
|
||||
return ResFAIL;
|
||||
|
||||
res = cbsBlockDescribe(cbsBlockOfTree(tree), stream);
|
||||
res = cbsBlockDescribe(NodeOfTree(tree), stream);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -673,8 +649,8 @@ static Res cbsFastBlockDescribe(CBSFastBlock block, mps_lib_FILE *stream)
|
|||
|
||||
res = WriteF(stream, 0,
|
||||
"[$P,$P) {$U}",
|
||||
(WriteFP)CBSBlockBase(&block->cbsBlockStruct),
|
||||
(WriteFP)CBSBlockLimit(&block->cbsBlockStruct),
|
||||
(WriteFP)NodeBase(cbsFastBlockNode(block)),
|
||||
(WriteFP)NodeLimit(cbsFastBlockNode(block)),
|
||||
(WriteFU)block->maxSize,
|
||||
NULL);
|
||||
return res;
|
||||
|
|
@ -702,8 +678,8 @@ static Res cbsZonedBlockDescribe(CBSZonedBlock block, mps_lib_FILE *stream)
|
|||
|
||||
res = WriteF(stream, 0,
|
||||
"[$P,$P) {$U, $B}",
|
||||
(WriteFP)CBSBlockBase(&block->cbsFastBlockStruct.cbsBlockStruct),
|
||||
(WriteFP)CBSBlockLimit(&block->cbsFastBlockStruct.cbsBlockStruct),
|
||||
(WriteFP)NodeBase(cbsZonedBlockNode(block)),
|
||||
(WriteFP)NodeLimit(cbsZonedBlockNode(block)),
|
||||
(WriteFU)block->cbsFastBlockStruct.maxSize,
|
||||
(WriteFB)block->zones,
|
||||
NULL);
|
||||
|
|
@ -739,9 +715,9 @@ static Bool cbsIterateVisit(Tree tree, void *closure)
|
|||
{
|
||||
CBSIterateClosure *my = closure;
|
||||
Land land = my->land;
|
||||
CBSBlock block = cbsBlockOfTree(tree);
|
||||
Node block = NodeOfTree(tree);
|
||||
RangeStruct range;
|
||||
RangeInit(&range, CBSBlockBase(block), CBSBlockLimit(block));
|
||||
RangeInit(&range, NodeBase(block), NodeLimit(block));
|
||||
return my->visitor(land, &range, my->visitorClosure);
|
||||
}
|
||||
|
||||
|
|
@ -786,11 +762,11 @@ static Bool cbsIterateAndDeleteVisit(Tree tree, void *closure)
|
|||
CBSIterateAndDeleteClosure *my = closure;
|
||||
Land land = my->land;
|
||||
CBS cbs = cbsOfLand(land);
|
||||
CBSBlock block = cbsBlockOfTree(tree);
|
||||
Node block = NodeOfTree(tree);
|
||||
Bool deleteNode = FALSE;
|
||||
RangeStruct range;
|
||||
|
||||
RangeInit(&range, CBSBlockBase(block), CBSBlockLimit(block));
|
||||
RangeInit(&range, NodeBase(block), NodeLimit(block));
|
||||
if (my->cont)
|
||||
my->cont = my->visitor(&deleteNode, land, &range,
|
||||
my->visitorClosure);
|
||||
|
|
@ -911,11 +887,11 @@ static Bool cbsFindFirst(Range rangeReturn, Range oldRangeReturn,
|
|||
found = SplayFindFirst(&tree, cbsSplay(cbs), &cbsTestNode,
|
||||
&cbsTestTree, &size);
|
||||
if (found) {
|
||||
CBSBlock block;
|
||||
Node block;
|
||||
RangeStruct range;
|
||||
block = cbsBlockOfTree(tree);
|
||||
AVER(CBSBlockSize(block) >= size);
|
||||
RangeInit(&range, CBSBlockBase(block), CBSBlockLimit(block));
|
||||
block = NodeOfTree(tree);
|
||||
AVER(NodeSize(block) >= size);
|
||||
RangeInit(&range, NodeBase(block), NodeLimit(block));
|
||||
AVER(RangeSize(&range) >= size);
|
||||
cbsFindDeleteRange(rangeReturn, oldRangeReturn, land, &range,
|
||||
size, findDelete);
|
||||
|
|
@ -944,7 +920,7 @@ typedef struct cbsTestNodeInZonesClosureStruct {
|
|||
static Bool cbsTestNodeInZones(SplayTree splay, Tree tree,
|
||||
void *closure)
|
||||
{
|
||||
CBSBlock block = cbsBlockOfTree(tree);
|
||||
Node block = NodeOfTree(tree);
|
||||
cbsTestNodeInZonesClosure my = closure;
|
||||
RangeInZoneSet search;
|
||||
|
||||
|
|
@ -953,7 +929,7 @@ static Bool cbsTestNodeInZones(SplayTree splay, Tree tree,
|
|||
search = my->high ? RangeInZoneSetLast : RangeInZoneSetFirst;
|
||||
|
||||
return search(&my->base, &my->limit,
|
||||
CBSBlockBase(block), CBSBlockLimit(block),
|
||||
NodeBase(block), NodeLimit(block),
|
||||
my->arena, my->zoneSet, my->size);
|
||||
}
|
||||
|
||||
|
|
@ -995,11 +971,11 @@ static Bool cbsFindLast(Range rangeReturn, Range oldRangeReturn,
|
|||
found = SplayFindLast(&tree, cbsSplay(cbs), &cbsTestNode,
|
||||
&cbsTestTree, &size);
|
||||
if (found) {
|
||||
CBSBlock block;
|
||||
Node block;
|
||||
RangeStruct range;
|
||||
block = cbsBlockOfTree(tree);
|
||||
AVER(CBSBlockSize(block) >= size);
|
||||
RangeInit(&range, CBSBlockBase(block), CBSBlockLimit(block));
|
||||
block = NodeOfTree(tree);
|
||||
AVER(NodeSize(block) >= size);
|
||||
RangeInit(&range, NodeBase(block), NodeLimit(block));
|
||||
AVER(RangeSize(&range) >= size);
|
||||
cbsFindDeleteRange(rangeReturn, oldRangeReturn, land, &range,
|
||||
size, findDelete);
|
||||
|
|
@ -1034,14 +1010,14 @@ static Bool cbsFindLargest(Range rangeReturn, Range oldRangeReturn,
|
|||
|
||||
maxSize = cbsFastBlockOfTree(SplayTreeRoot(cbsSplay(cbs)))->maxSize;
|
||||
if (maxSize >= size) {
|
||||
CBSBlock block;
|
||||
Node block;
|
||||
METER_ACC(cbs->treeSearch, cbs->treeSize);
|
||||
found = SplayFindFirst(&tree, cbsSplay(cbs), &cbsTestNode,
|
||||
&cbsTestTree, &maxSize);
|
||||
AVER(found); /* maxSize is exact, so we will find it. */
|
||||
block = cbsBlockOfTree(tree);
|
||||
AVER(CBSBlockSize(block) >= maxSize);
|
||||
RangeInit(&range, CBSBlockBase(block), CBSBlockLimit(block));
|
||||
block = NodeOfTree(tree);
|
||||
AVER(NodeSize(block) >= maxSize);
|
||||
RangeInit(&range, NodeBase(block), NodeLimit(block));
|
||||
AVER(RangeSize(&range) >= maxSize);
|
||||
cbsFindDeleteRange(rangeReturn, oldRangeReturn, land, &range,
|
||||
size, findDelete);
|
||||
|
|
@ -1057,7 +1033,7 @@ static Res cbsFindInZones(Bool *foundReturn, Range rangeReturn,
|
|||
ZoneSet zoneSet, Bool high)
|
||||
{
|
||||
CBS cbs;
|
||||
CBSBlock block;
|
||||
Node block;
|
||||
Tree tree;
|
||||
cbsTestNodeInZonesClosureStruct closure;
|
||||
Res res;
|
||||
|
|
@ -1100,12 +1076,12 @@ static Res cbsFindInZones(Bool *foundReturn, Range rangeReturn,
|
|||
&closure))
|
||||
goto fail;
|
||||
|
||||
block = cbsBlockOfTree(tree);
|
||||
block = NodeOfTree(tree);
|
||||
|
||||
AVER(CBSBlockBase(block) <= closure.base);
|
||||
AVER(NodeBase(block) <= closure.base);
|
||||
AVER(AddrOffset(closure.base, closure.limit) >= size);
|
||||
AVER(ZoneSetSub(ZoneSetOfRange(LandArena(land), closure.base, closure.limit), zoneSet));
|
||||
AVER(closure.limit <= CBSBlockLimit(block));
|
||||
AVER(closure.limit <= NodeLimit(block));
|
||||
|
||||
if (!high)
|
||||
RangeInit(&rangeStruct, closure.base, AddrAdd(closure.base, size));
|
||||
|
|
|
|||
|
|
@ -15,15 +15,9 @@
|
|||
#include "range.h"
|
||||
#include "splay.h"
|
||||
|
||||
typedef struct CBSBlockStruct *CBSBlock;
|
||||
typedef struct CBSBlockStruct {
|
||||
TreeStruct treeStruct;
|
||||
RangeStruct rangeStruct;
|
||||
} CBSBlockStruct;
|
||||
|
||||
typedef struct CBSFastBlockStruct *CBSFastBlock;
|
||||
typedef struct CBSFastBlockStruct {
|
||||
struct CBSBlockStruct cbsBlockStruct;
|
||||
struct NodeStruct nodeStruct;
|
||||
Size maxSize; /* accurate maximum block size of sub-tree */
|
||||
} CBSFastBlockStruct;
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,12 @@
|
|||
#define NodeOfTree(tree) PARENT(NodeStruct, treeStruct, tree)
|
||||
#define NodeOfRange(range) PARENT(NodeStruct, rangeStruct, range)
|
||||
|
||||
#define NodeBase(block) RangeBase(NodeRange(block))
|
||||
#define NodeLimit(block) RangeLimit(NodeRange(block))
|
||||
#define NodeSetBase(block, addr) RangeSetBase(NodeRange(block), addr)
|
||||
#define NodeSetLimit(block, addr) RangeSetLimit(NodeRange(block), addr)
|
||||
#define NodeSize(block) RangeSize(NodeRange(block))
|
||||
|
||||
extern void NodeInit(Node node, Addr base, Addr limit);
|
||||
extern Bool NodeCheck(Node node);
|
||||
extern void NodeFinish(Node node);
|
||||
|
|
|
|||
|
|
@ -41,13 +41,6 @@ extern Size (RangeSize)(Range range);
|
|||
extern void RangeCopy(Range to, Range from);
|
||||
|
||||
|
||||
/* Types */
|
||||
|
||||
typedef struct RangeStruct {
|
||||
Addr base;
|
||||
Addr limit;
|
||||
} RangeStruct;
|
||||
|
||||
#endif /* range_h */
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue