From: Brian Norris <banorris@uci.edu>
Date: Tue, 2 Oct 2012 00:30:01 +0000 (-0700)
Subject: clockvector: snapshot our clock vectors
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=3dbbf345d69d35d3f763fd59bb6d2bc9d9530e98;p=cdsspec-compiler.git

clockvector: snapshot our clock vectors

Clock vectors need to be snapshotted
---

diff --git a/action.cc b/action.cc
index c744c65..0063d0b 100644
--- 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
diff --git a/clockvector.cc b/clockvector.cc
index 594daa8..c5bf077 100644
--- a/clockvector.cc
+++ b/clockvector.cc
@@ -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;
 }