summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxim Zhiburt <zhiburt@gmail.com>2020-11-22 21:36:07 +0300
committerBenBE <BenBE@geshi.org>2020-12-02 23:50:05 +0100
commit4907d90cffde5cdba4ccf427db9c7a5ad4e4c733 (patch)
treea96c94e2fbfaf9c551c0b4cf9a2b405a53e0924c
parentcf306ff86e44361d8cf3aaaec568b20fb8bbfa3d (diff)
Fix issue with inconsistent displayTreeSet
-rw-r--r--ProcessList.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/ProcessList.c b/ProcessList.c
index 00457c02..9597fcb9 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -241,6 +241,10 @@ static void ProcessList_updateTreeSetLayer(ProcessList* this, unsigned int leftB
}
Hashtable_put(this->draftingTreeSet, proc->tree_index, proc);
+
+ // It's not strictly necessary to do this, but doing so anyways
+ // allows for checking the correctness of the inner workings.
+ Hashtable_remove(this->displayTreeSet, newLeftBound);
}
Vector_delete(layer);
@@ -249,15 +253,20 @@ static void ProcessList_updateTreeSetLayer(ProcessList* this, unsigned int leftB
static void ProcessList_updateTreeSet(ProcessList* this) {
unsigned int index = 0;
unsigned int tree_index = 1;
- int vsize = Vector_size(this->processes);
- ProcessList_updateTreeSetLayer(this, 0, vsize, 0, 0, vsize*2+1, &index, &tree_index, -1);
- assert((int)Hashtable_count(this->draftingTreeSet) == vsize);
+ const int vsize = Vector_size(this->processes);
- for(int i = 0; i < vsize; i++) {
- Process* proc = (Process*)Hashtable_remove(this->draftingTreeSet, i);
- Hashtable_put(this->displayTreeSet, i, proc);
- }
+ assert(Hashtable_count(this->draftingTreeSet) == 0);
+ assert((int)Hashtable_count(this->displayTreeSet) == vsize);
+
+ ProcessList_updateTreeSetLayer(this, 0, vsize, 0, 0, vsize * 2 + 1, &index, &tree_index, -1);
+
+ Hashtable* tmp = this->draftingTreeSet;
+ this->draftingTreeSet = this->displayTreeSet;
+ this->displayTreeSet = tmp;
+
+ assert(Hashtable_count(this->draftingTreeSet) == 0);
+ assert((int)Hashtable_count(this->displayTreeSet) == vsize);
}
static void ProcessList_buildTreeBranch(ProcessList* this, pid_t pid, int level, int indent, int direction, bool show, int* node_counter, int* node_index) {
@@ -530,5 +539,11 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) {
}
}
+ // Clear out the hashtable to avoid any left-over processes from previous build
+ //
+ // The sorting algorithm relies on the fact that
+ // len(this->displayTreeSet) == len(this->processes)
+ Hashtable_clear(this->displayTreeSet);
+
ProcessList_buildTree(this);
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy