clockvector: snapshot our clock vectors
authorBrian Norris <banorris@uci.edu>
Tue, 2 Oct 2012 00:30:01 +0000 (17:30 -0700)
committerBrian Norris <banorris@uci.edu>
Tue, 2 Oct 2012 00:40:19 +0000 (17:40 -0700)
Clock vectors need to be snapshotted

action.cc
clockvector.cc

index c744c65f1b5b06223ea08618c3ea1d1700b6c500..0063d0b27169f29dbe46d2fa71c3535fea2abc9c 100644 (file)
--- a/action.cc
+++ b/action.cc
@@ -201,11 +201,16 @@ bool ModelAction::is_conflicting_lock(const ModelAction *act) const
        return false;
 }
 
+/**
+ * Create a new clock vector for this action. Note that this function allows a
+ * user to clobber (and leak) a ModelAction's existing clock vector. A user
+ * should ensure that the vector has already either been rolled back
+ * (effectively "freed") or freed.
+ *
+ * @param parent A ModelAction from which to inherit a ClockVector
+ */
 void ModelAction::create_cv(const ModelAction *parent)
 {
-       if (cv)
-               delete cv;
-
        if (parent)
                cv = new ClockVector(parent->cv, this);
        else
index 594daa8a75d968f500d3248085045a559c3e13fa..c5bf07709b718f775f0337f6b360f273081c3e08 100644 (file)
@@ -18,8 +18,7 @@
 ClockVector::ClockVector(ClockVector *parent, ModelAction *act)
 {
        num_threads = model->get_num_threads();
-       clock = (modelclock_t *)MYMALLOC(num_threads * sizeof(int));
-       memset(clock, 0, num_threads * sizeof(int));
+       clock = (modelclock_t *)snapshot_calloc(num_threads, sizeof(int));
        if (parent)
                std::memcpy(clock, parent->clock, parent->num_threads * sizeof(modelclock_t));
 
@@ -30,7 +29,7 @@ ClockVector::ClockVector(ClockVector *parent, ModelAction *act)
 /** @brief Destructor */
 ClockVector::~ClockVector()
 {
-       MYFREE(clock);
+       snapshot_free(clock);
 }
 
 /**
@@ -47,7 +46,7 @@ void ClockVector::merge(const ClockVector *cv)
 
        if (cv->num_threads > num_threads) {
                resize = true;
-               clk = (modelclock_t *)MYMALLOC(cv->num_threads * sizeof(modelclock_t));
+               clk = (modelclock_t *)snapshot_malloc(cv->num_threads * sizeof(modelclock_t));
        }
 
        /* Element-wise maximum */
@@ -58,7 +57,7 @@ void ClockVector::merge(const ClockVector *cv)
                for (int i = num_threads; i < cv->num_threads; i++)
                        clk[i] = cv->clock[i];
                num_threads = cv->num_threads;
-               MYFREE(clock);
+               snapshot_free(clock);
        }
        clock = clk;
 }