X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11tester.git;a=blobdiff_plain;f=actionlist.cc;h=f97e667a00c9a20273bbd7e146b4543d96776eda;hp=9f335e900e2de1910bf7e1a75531b04a64cb56a7;hb=25d73096cfc14c655f94b01bb235cc5efd1d5696;hpb=17a2aadccd57b9cf65a4a2b239153c57e9192e27 diff --git a/actionlist.cc b/actionlist.cc index 9f335e90..f97e667a 100644 --- a/actionlist.cc +++ b/actionlist.cc @@ -5,17 +5,19 @@ #include actionlist::actionlist() : - head(NULL), - tail(NULL), - _size(0) + root(), + head(NULL), + tail(NULL), + _size(0) { - root.parent = NULL; } actionlist::~actionlist() { + clear(); } allnode::allnode() : + parent(NULL), count(0) { bzero(children, sizeof(children)); } @@ -31,13 +33,11 @@ allnode::~allnode() { sllnode * allnode::findPrev(modelclock_t index) { allnode * ptr = this; modelclock_t increment = 1; - modelclock_t mask = ALLMASK; int totalshift = 0; index -= increment; while(1) { - modelclock_t shiftclock = index >> totalshift; - modelclock_t currindex = shiftclock & ALLMASK; + modelclock_t currindex = (index >> totalshift) & ALLMASK; //See if we went negative... if (currindex != ALLMASK) { @@ -48,11 +48,10 @@ sllnode * allnode::findPrev(modelclock_t index) { } else { //found non-null... if (totalshift == 0) - return reinterpret_cast *>(((uintptr_t)ptr->children[currindex])& ACTMASK); + return reinterpret_cast *>(((uintptr_t)ptr->children[currindex])& ACTMASK); //need to increment here... ptr = ptr->children[currindex]; increment = increment >> ALLBITS; - mask = mask >> ALLBITS; totalshift -= ALLBITS; break; } @@ -60,7 +59,6 @@ sllnode * allnode::findPrev(modelclock_t index) { //If we get here, we already did the decrement earlier...no need to decrement again ptr = ptr->parent; increment = increment << ALLBITS; - mask = mask << ALLBITS; totalshift += ALLBITS; if (ptr == NULL) { @@ -70,8 +68,7 @@ sllnode * allnode::findPrev(modelclock_t index) { while(1) { while(1) { - modelclock_t shiftclock = index >> totalshift; - modelclock_t currindex = shiftclock & ALLMASK; + modelclock_t currindex = (index >> totalshift) & ALLMASK; if (ptr->children[currindex] != NULL) { if (totalshift != 0) { ptr = ptr->children[currindex]; @@ -86,7 +83,6 @@ sllnode * allnode::findPrev(modelclock_t index) { } increment = increment >> ALLBITS; - mask = mask >> ALLBITS; totalshift -= ALLBITS; } } @@ -98,25 +94,22 @@ void actionlist::addAction(ModelAction * act) { allnode * ptr = &root; do { - int index = (clock >> shiftbits) & ALLMASK; - allnode * tmp = ptr->children[index]; + modelclock_t currindex = (clock >> shiftbits) & ALLMASK; + allnode * tmp = ptr->children[currindex]; if (shiftbits == 0) { sllnode * llnode = new sllnode(); llnode->val = act; if (tmp == NULL) { - ptr->children[index] = reinterpret_cast(((uintptr_t) llnode) | ISACT); sllnode * llnodeprev = ptr->findPrev(clock); if (llnodeprev != NULL) { - llnode->next = llnodeprev->next; llnode->prev = llnodeprev; //see if we are the new tail - if (llnodeprev->next == NULL) - tail = llnode; - else + if (llnode->next != NULL) llnode->next->prev = llnode; - + else + tail = llnode; llnodeprev->next = llnode; } else { //We are the begining @@ -131,23 +124,27 @@ void actionlist::addAction(ModelAction * act) { head = llnode; } + ptr->children[currindex] = reinterpret_cast(((uintptr_t) llnode) | ISACT); + //need to find next link ptr->count++; } else { //handle case where something else is here - sllnode * llnodeprev = reinterpret_cast*>(((uintptr_t) llnode) & ACTMASK); + sllnode * llnodeprev = reinterpret_cast*>(((uintptr_t) tmp) & ACTMASK); llnode->next = llnodeprev->next; llnode->prev = llnodeprev; if (llnode->next != NULL) - llnode->next->prev = llnode; + llnode->next->prev = llnode; + else + tail = llnode; llnodeprev->next = llnode; - ptr->children[index] = reinterpret_cast(((uintptr_t) llnode) | ISACT); + ptr->children[currindex] = reinterpret_cast(((uintptr_t) llnode) | ISACT); } return; } else if (tmp == NULL) { tmp = new allnode(); - ptr->children[index] = tmp; + ptr->children[currindex] = tmp; tmp->parent=ptr; ptr->count++; } @@ -165,69 +162,66 @@ void decrementCount(allnode * ptr) { if (ptr->parent->children[i]==ptr) { ptr->parent->children[i] = NULL; decrementCount(ptr->parent); + break; } } + delete ptr; } - delete ptr; } } void actionlist::removeAction(ModelAction * act) { - int shiftbits = MODELCLOCKBITS - ALLBITS; + int shiftbits = MODELCLOCKBITS; modelclock_t clock = act->get_seq_number(); allnode * ptr = &root; + allnode * oldptr; + modelclock_t currindex; + + while(shiftbits != 0) { + shiftbits -= ALLBITS; + currindex = (clock >> shiftbits) & ALLMASK; + oldptr = ptr; + ptr = ptr->children[currindex]; + if (ptr == NULL) + return; + } + + sllnode * llnode = reinterpret_cast *>(((uintptr_t) ptr) & ACTMASK); + bool first = true; do { - int index = (clock >> shiftbits) & ALLMASK; - allnode * tmp = ptr->children[index]; - if (shiftbits == 0) { - if (tmp == NULL) { - //not found - return; + if (llnode->val == act) { + //found node to remove + sllnode * llnodeprev = llnode->prev; + sllnode * llnodenext = llnode->next; + if (llnodeprev != NULL) { + llnodeprev->next = llnodenext; } else { - sllnode * llnode = reinterpret_cast *>(((uintptr_t) tmp) & ACTMASK); - bool first = true; - do { - if (llnode->val == act) { - //found node to remove - sllnode * llnodeprev = llnode->prev; - sllnode * llnodenext = llnode->next; - if (llnodeprev != NULL) { - llnodeprev->next = llnodenext; - } else { - head = llnodenext; - } - if (llnodenext != NULL) { - llnodenext->prev = llnodeprev; - } else { - tail = llnodeprev; - } - if (first) { - //see if previous node has same clock as us... - if (llnodeprev->val->get_seq_number() == clock) { - ptr->children[index] = reinterpret_cast(((uintptr_t)llnodeprev) | ISACT); - } else { - //remove ourselves and go up tree - ptr->children[index] = NULL; - decrementCount(ptr); - } - } - delete llnode; - _size--; - return; - } - llnode = llnode->prev; - first = false; - } while(llnode != NULL && llnode->val->get_seq_number() == clock); - //node not found in list... no deletion - return; + head = llnodenext; } - } else if (tmp == NULL) { - //not found + if (llnodenext != NULL) { + llnodenext->prev = llnodeprev; + } else { + tail = llnodeprev; + } + if (first) { + //see if previous node has same clock as us... + if (llnodeprev != NULL && llnodeprev->val->get_seq_number() == clock) { + oldptr->children[currindex] = reinterpret_cast(((uintptr_t)llnodeprev) | ISACT); + } else { + //remove ourselves and go up tree + oldptr->children[currindex] = NULL; + decrementCount(oldptr); + } + } + delete llnode; + _size--; return; } - shiftbits -= ALLBITS; - ptr = tmp; - } while(1); + llnode = llnode->prev; + first = false; + } while(llnode != NULL && llnode->val->get_seq_number() == clock); + //node not found in list... no deletion + return; } void actionlist::clear() { @@ -243,7 +237,7 @@ void actionlist::clear() { delete head; head = tmp; } - tail=NULL; + tail = NULL; root.count = 0; _size = 0; @@ -252,3 +246,16 @@ void actionlist::clear() { bool actionlist::isEmpty() { return root.count == 0; } + +/** + * Fix the parent pointer of root when root address changes (possible + * due to vector resize) + */ +void actionlist::fixupParent() +{ + for (int i = 0;i < ALLNODESIZE;i++) { + allnode * child = root.children[i]; + if (child != NULL && child->parent != &root) + child->parent = &root; + } +}