promise: add max_available_thread_idx() interface
authorBrian Norris <banorris@uci.edu>
Tue, 16 Apr 2013 18:45:51 +0000 (11:45 -0700)
committerBrian Norris <banorris@uci.edu>
Tue, 16 Apr 2013 18:45:51 +0000 (11:45 -0700)
To remove an unnecessary use of global/public model->get_num_threads().

cyclegraph.cc
promise.cc
promise.h

index 0ec95b057bec48bce7d914e316066c2c62de065c..7e5e95602408b47f5d4ff5b746e64db88287366f 100644 (file)
@@ -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;
index df86090a2335ff3e17c69d33a98c9d370903f199..3a38384721cd3dfdc59b25f59440b432cf62c87b 100644 (file)
@@ -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
 {
index 1560b5809dec9672310c5a65fb3c9c28f3841309..84d5aa49b3af7b8156ef4744e270f128c6a0cabf 100644 (file)
--- 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; }