From: Brian Norris <banorris@uci.edu>
Date: Tue, 16 Apr 2013 18:45:51 +0000 (-0700)
Subject: promise: add max_available_thread_idx() interface
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6070a45c81428a5e09909d4beb325150aefd0c52;p=c11tester.git

promise: add max_available_thread_idx() interface

To remove an unnecessary use of global/public model->get_num_threads().
---

diff --git a/cyclegraph.cc b/cyclegraph.cc
index 0ec95b05..7e5e9560 100644
--- a/cyclegraph.cc
+++ b/cyclegraph.cc
@@ -2,7 +2,6 @@
 #include "action.h"
 #include "common.h"
 #include "promise.h"
-#include "model.h"
 #include "threads-model.h"
 
 /** Initializes a CycleGraph object. */
@@ -319,7 +318,7 @@ static void print_node(FILE *file, const CycleNode *node, int label)
 		if (label) {
 			int first = 1;
 			fprintf(file, " [label=\"P%d, T", idx);
-			for (unsigned int i = 0 ; i < model->get_num_threads(); i++)
+			for (unsigned int i = 0 ; i < promise->max_available_thread_idx(); i++)
 				if (promise->thread_is_available(int_to_id(i))) {
 					fprintf(file, "%s%u", first ? "": ",", i);
 					first = 0;
diff --git a/promise.cc b/promise.cc
index df86090a..3a383847 100644
--- a/promise.cc
+++ b/promise.cc
@@ -100,6 +100,19 @@ bool Promise::thread_is_available(thread_id_t tid) const
 	return available_thread[id];
 }
 
+/**
+ * @brief Get an upper bound on the number of available threads
+ *
+ * Gets an upper bound on the number of threads in the available threads set,
+ * useful for iterating over "thread_is_available()".
+ *
+ * @return The upper bound
+ */
+unsigned int Promise::max_available_thread_idx() const
+{
+	return available_thread.size();
+}
+
 /** @brief Print debug info about the Promise */
 void Promise::print() const
 {
diff --git a/promise.h b/promise.h
index 1560b580..84d5aa49 100644
--- a/promise.h
+++ b/promise.h
@@ -31,6 +31,7 @@ class Promise {
 	bool eliminate_thread(thread_id_t tid);
 	void add_thread(thread_id_t tid);
 	bool thread_is_available(thread_id_t tid) const;
+	unsigned int max_available_thread_idx() const;
 	bool has_failed() const;
 	void set_write(const ModelAction *act) { write = act; }
 	const ModelAction * get_write() const { return write; }