summaryrefslogtreecommitdiffstats
path: root/include/framework/DynamicExtension.h
diff options
context:
space:
mode:
authorDouglas Rumbaugh <dbr4@psu.edu>2023-11-15 15:18:33 -0500
committerDouglas Rumbaugh <dbr4@psu.edu>2023-11-15 15:18:33 -0500
commitfe12926c41eed825da80a36d77b7facd9ba0567a (patch)
treec30c62803327963b2c4e967fed9c26a515ef4de1 /include/framework/DynamicExtension.h
parent90bb0614fc1d8f1a185a778e31aaf9027c01aeb8 (diff)
downloaddynamic-extension-fe12926c41eed825da80a36d77b7facd9ba0567a.tar.gz
Lock protect Epoch during retirement to avoid use-after-free errors
Diffstat (limited to 'include/framework/DynamicExtension.h')
-rw-r--r--include/framework/DynamicExtension.h27
1 files changed, 16 insertions, 11 deletions
diff --git a/include/framework/DynamicExtension.h b/include/framework/DynamicExtension.h
index 9adc320..8edcc5f 100644
--- a/include/framework/DynamicExtension.h
+++ b/include/framework/DynamicExtension.h
@@ -14,6 +14,8 @@
#include <cstdio>
#include <vector>
#include <set>
+#include <shared_mutex>
+#include <mutex>
#include "framework/structure/MutableBuffer.h"
#include "framework/structure/InternalLevel.h"
@@ -247,6 +249,7 @@ private:
std::mutex m_epoch_cv_lk;
std::mutex m_epoch_transition_lk;
+ std::shared_mutex m_epoch_retire_lk;
size_t m_scale_factor;
double m_max_delete_prop;
@@ -284,15 +287,10 @@ private:
}
_Epoch *get_active_epoch_protected() {
- ssize_t cur_epoch = -1;
- do {
- if (cur_epoch != -1) {
- m_epochs[cur_epoch]->end_job();
- }
-
- cur_epoch = m_current_epoch.load();
- m_epochs[cur_epoch]->start_job();
- } while (cur_epoch != m_current_epoch.load());
+ m_epoch_retire_lk.lock_shared();
+ auto cur_epoch = m_current_epoch.load();
+ m_epochs[cur_epoch]->start_job();
+ m_epoch_retire_lk.unlock_shared();
return m_epochs[cur_epoch];
}
@@ -429,8 +427,14 @@ private:
* number will hit zero and the function will
* proceed.
*/
- while (!epoch->retirable())
- ;
+
+ do {
+ m_epoch_retire_lk.lock();
+ if (epoch->retirable()) {
+ break;
+ }
+ m_epoch_retire_lk.unlock();
+ } while (true);
/* remove epoch from the framework's map */
m_epochs.erase(epoch->get_epoch_number());
@@ -440,6 +444,7 @@ private:
* all the references it holds
*/
delete epoch;
+ m_epoch_retire_lk.unlock();
/*
* Following the epoch's destruction, any buffers