From 596b1d23fb2612df9ae569f17dbb3017a6e0aef7 Mon Sep 17 00:00:00 2001
From: Brian Norris <banorris@uci.edu>
Date: Thu, 12 Jul 2012 17:43:47 -0700
Subject: [PATCH] model: add ModelChecker::get_last_seq_cst()

Add a function to get the last memory_order_seq_cst action (in the total global
sequence) performed on a particular object (i.e., memory location). Will be
used for build_reads_from_past().
---
 model.cc | 17 +++++++++++++++++
 model.h  |  1 +
 2 files changed, 18 insertions(+)

diff --git a/model.cc b/model.cc
index aef7cb9..8e6e1b8 100644
--- a/model.cc
+++ b/model.cc
@@ -320,6 +320,23 @@ ModelAction * ModelChecker::get_last_action(thread_id_t tid)
 	return (*thrd_last_action)[id_to_int(tid)];
 }
 
+/**
+ * Gets the last memory_order_seq_cst action (in the total global sequence)
+ * performed on a particular object (i.e., memory location).
+ * @param location The object location to check
+ * @return The last seq_cst action performed
+ */
+ModelAction * ModelChecker::get_last_seq_cst(const void *location)
+{
+	action_list_t *list = &(*obj_map)[location];
+	/* Find: max({i in dom(S) | seq_cst(t_i) && isWrite(t_i) && samevar(t_i, t)}) */
+	action_list_t::reverse_iterator rit;
+	for (rit = list->rbegin(); rit != list->rend(); rit++)
+		if ((*rit)->is_write() && (*rit)->is_seqcst())
+			return *rit;
+	return NULL;
+}
+
 ModelAction * ModelChecker::get_parent_action(thread_id_t tid)
 {
 	ModelAction *parent = get_last_action(tid);
diff --git a/model.h b/model.h
index 5d74b84..e62ff00 100644
--- a/model.h
+++ b/model.h
@@ -80,6 +80,7 @@ private:
 	void add_action_to_lists(ModelAction *act);
 	ModelAction * get_last_action(thread_id_t tid);
 	ModelAction * get_parent_action(thread_id_t tid);
+	ModelAction * get_last_seq_cst(const void *location);
 	void build_reads_from_past(ModelAction *curr);
 
 	ModelAction *current_action;
-- 
2.34.1