From 196c536e1147bc82d50c8e1536d91c77ecb6d428 Mon Sep 17 00:00:00 2001 From: weiyu Date: Tue, 14 Apr 2020 19:03:41 -0700 Subject: [PATCH] Fix bug when vectors of action lists get reallocated --- actionlist.cc | 13 +++++++++++++ actionlist.h | 1 + execution.cc | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/actionlist.cc b/actionlist.cc index 0dc8bc89..4a24ba99 100644 --- a/actionlist.cc +++ b/actionlist.cc @@ -246,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; + } +} diff --git a/actionlist.h b/actionlist.h index 20f93fc9..ee0a1445 100644 --- a/actionlist.h +++ b/actionlist.h @@ -41,6 +41,7 @@ public: uint size() {return _size;} sllnode * begin() {return head;} sllnode * end() {return tail;} + void fixupParent(); SNAPSHOTALLOC; diff --git a/execution.cc b/execution.cc index c37de41a..7f7d31c1 100644 --- a/execution.cc +++ b/execution.cc @@ -118,6 +118,20 @@ static SnapVector * get_safe_ptr_vect_action(HashTable * vec) +{ + for (uint i = 0; i < vec->size(); i++) { + action_list_t * list = &(*vec)[i]; + if (list != NULL) + list->fixupParent(); + } +} + /** @return a thread ID for a new Thread */ thread_id_t ModelExecution::get_next_id() { @@ -785,6 +799,8 @@ bool ModelExecution::r_modification_order(ModelAction *curr, const ModelAction * thrd_lists->resize(priv->next_thread_id); for(uint i = oldsize;i < priv->next_thread_id;i++) new (&(*thrd_lists)[i]) action_list_t(); + + fixup_action_list(thrd_lists); } ModelAction *prev_same_thread = NULL; @@ -1120,6 +1136,8 @@ void ModelExecution::add_action_to_lists(ModelAction *act, bool canprune) vec->resize(priv->next_thread_id); for(uint i = oldsize;i < priv->next_thread_id;i++) new (&(*vec)[i]) action_list_t(); + + fixup_action_list(vec); } if (!canprune && (act->is_read() || act->is_write())) (*vec)[tid].addAction(act); @@ -1171,6 +1189,8 @@ void ModelExecution::add_normal_write_to_lists(ModelAction *act) vec->resize(priv->next_thread_id); for(uint i=oldsize;inext_thread_id;i++) new (&(*vec)[i]) action_list_t(); + + fixup_action_list(vec); } insertIntoActionList(&(*vec)[tid],act); @@ -1189,6 +1209,8 @@ void ModelExecution::add_write_to_lists(ModelAction *write) { vec->resize(priv->next_thread_id); for(uint i=oldsize;inext_thread_id;i++) new (&(*vec)[i]) action_list_t(); + + fixup_action_list(vec); } (*vec)[tid].addAction(write); } -- 2.34.1