Stupid bugs.
This commit is contained in:
parent
7dca7fd327
commit
4636a37a27
|
@ -43,34 +43,37 @@ void BorderServer::AddBorder(unsigned short nbord, unsigned int used) {
|
||||||
Redim(entry.start * sizeof(Link) + nbord * sizeof(Link));
|
Redim(entry.start * sizeof(Link) + nbord * sizeof(Link));
|
||||||
}
|
}
|
||||||
|
|
||||||
Border BorderServer::GetBorder(unsigned int border, bool flush) {
|
Border BorderServer::GetBorder(unsigned int border, bool flush) {
|
||||||
BorderEntry &entry = operator[](border);
|
BorderEntry &entry = operator[](border);
|
||||||
|
//assert(entry.size != 0);
|
||||||
if(index.count(border)) {
|
if(index.count(border)) {
|
||||||
assert(entry.links);
|
//assert(entry.links);
|
||||||
list<unsigned int>::iterator &i = index[border];
|
list<unsigned int>::iterator i = index[border];
|
||||||
pqueue.erase(i);
|
pqueue.erase(i);
|
||||||
pqueue.push_front(border);
|
pqueue.push_front(border);
|
||||||
|
index[border] = pqueue.begin();
|
||||||
} else {
|
} else {
|
||||||
while(flush && ram_used > ram_max) {
|
while(flush && ram_used > ram_max) {
|
||||||
|
assert(pqueue.size());
|
||||||
unsigned int to_flush = pqueue.back();
|
unsigned int to_flush = pqueue.back();
|
||||||
pqueue.pop_back();
|
pqueue.pop_back();
|
||||||
index.erase(to_flush);
|
index.erase(to_flush);
|
||||||
FlushBorder(to_flush);
|
FlushBorder(to_flush);
|
||||||
}
|
}
|
||||||
assert(!entry.links);
|
assert(!entry.links);
|
||||||
entry.links = GetRegion(entry.start, entry.size);
|
if(entry.size != 0)
|
||||||
pqueue.push_front(border);
|
entry.links = GetRegion(entry.start, entry.size);
|
||||||
list<unsigned int>::iterator i = pqueue.begin();
|
pqueue.push_front(border);
|
||||||
index[border] = i;
|
index[border] = pqueue.begin();
|
||||||
ram_used += entry.size;
|
ram_used += entry.size;
|
||||||
}
|
}
|
||||||
return Border(entry.links, entry.used, entry.size);
|
return Border(entry.links, entry.used, entry.size);
|
||||||
}
|
}
|
||||||
|
//TODO Change when remving borderentry class.
|
||||||
bool BorderServer::ResizeBorder(unsigned int border, unsigned int nbord) {
|
bool BorderServer::ResizeBorder(unsigned int border, unsigned int nbord) {
|
||||||
assert(nbord < 65500);
|
assert(nbord < 65500);
|
||||||
assert(border < size());
|
assert(border < size());
|
||||||
|
GetBorder(border);
|
||||||
BorderEntry &entry = operator[](border);
|
BorderEntry &entry = operator[](border);
|
||||||
if(nbord > entry.size) {
|
if(nbord > entry.size) {
|
||||||
int capacity = nbord;
|
int capacity = nbord;
|
||||||
|
@ -80,11 +83,12 @@ bool BorderServer::ResizeBorder(unsigned int border, unsigned int nbord) {
|
||||||
capacity = 65500;
|
capacity = 65500;
|
||||||
unsigned int newstart = Length()/sizeof(Link);
|
unsigned int newstart = Length()/sizeof(Link);
|
||||||
Redim((newstart + capacity) * sizeof(Link));
|
Redim((newstart + capacity) * sizeof(Link));
|
||||||
|
Link *dst = GetRegion(newstart, capacity);
|
||||||
if(entry.used > 0) {
|
if(entry.used > 0) {
|
||||||
Link *src = GetRegion(entry.start, entry.size);
|
Link *src = GetRegion(entry.start, entry.size);
|
||||||
Link *dst = GetRegion(newstart, capacity);
|
|
||||||
memcpy(dst, src, entry.used * sizeof(Link));
|
memcpy(dst, src, entry.used * sizeof(Link));
|
||||||
}
|
}
|
||||||
|
entry.links = dst;
|
||||||
entry.start = newstart;
|
entry.start = newstart;
|
||||||
entry.size = capacity;
|
entry.size = capacity;
|
||||||
entry.used = nbord;
|
entry.used = nbord;
|
||||||
|
@ -96,18 +100,19 @@ bool BorderServer::ResizeBorder(unsigned int border, unsigned int nbord) {
|
||||||
|
|
||||||
void BorderServer::FlushBorder(unsigned int border) {
|
void BorderServer::FlushBorder(unsigned int border) {
|
||||||
BorderEntry &entry = operator[](border);
|
BorderEntry &entry = operator[](border);
|
||||||
assert(entry.links);
|
//assert(entry.links);
|
||||||
if(!MFile::IsReadOnly()) { //write back patch
|
if(entry.size && !MFile::IsReadOnly()) { //write back patch
|
||||||
MFile::SetPosition((int64)entry.start * sizeof(Link));
|
MFile::SetPosition((int64)entry.start * sizeof(Link));
|
||||||
MFile::WriteBuffer(entry.links, entry.used * sizeof(Link));
|
MFile::WriteBuffer(entry.links, entry.used * sizeof(Link));
|
||||||
}
|
}
|
||||||
|
if(entry.size)
|
||||||
delete [](entry.links);
|
delete [](entry.links);
|
||||||
entry.links = NULL;
|
entry.links = NULL;
|
||||||
ram_used -= entry.size;
|
ram_used -= entry.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
Link *BorderServer::GetRegion(unsigned int start, unsigned int size) {
|
Link *BorderServer::GetRegion(unsigned int start, unsigned int size) {
|
||||||
|
assert(size > 0);
|
||||||
SetPosition(start * sizeof(Link));
|
SetPosition(start * sizeof(Link));
|
||||||
Link *buf = new Link[size];
|
Link *buf = new Link[size];
|
||||||
assert(buf);
|
assert(buf);
|
||||||
|
|
|
@ -15,9 +15,10 @@
|
||||||
|
|
||||||
namespace nxs {
|
namespace nxs {
|
||||||
|
|
||||||
|
//This should be Border class!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
struct BorderEntry {
|
struct BorderEntry {
|
||||||
unsigned int start; //granuralita' Link
|
unsigned int start; //granuralita' Link
|
||||||
unsigned short size; //in Links
|
unsigned short size; //in Links //TODO what are this? be clear!
|
||||||
unsigned short used; //in Links
|
unsigned short used; //in Links
|
||||||
Link *links;
|
Link *links;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue