Fix snapshot code
[model-checker.git] / promise.cc
index 26a1095f4440a4b65d80dd67917da2f423ab28fe..a98403bbcf10569a91c2929bd17c420f4a3dc5f6 100644 (file)
@@ -2,18 +2,21 @@
 #include <inttypes.h>
 
 #include "promise.h"
-#include "model.h"
+#include "execution.h"
 #include "schedule.h"
 #include "action.h"
 #include "threads-model.h"
 
 /**
  * @brief Promise constructor
+ * @param execution The execution which is creating this Promise
  * @param read The read which reads from a promised future value
  * @param fv The future value that is promised
  */
-Promise::Promise(ModelAction *read, struct future_value fv) :
+Promise::Promise(const ModelExecution *execution, ModelAction *read, struct future_value fv) :
+       execution(execution),
        num_available_threads(0),
+       num_was_available_threads(0),
        fv(fv),
        readers(1, read),
        write(NULL)
@@ -80,6 +83,12 @@ void Promise::add_thread(thread_id_t tid)
                available_thread[id] = true;
                num_available_threads++;
        }
+       if (id >= was_available_thread.size())
+               was_available_thread.resize(id + 1, false);
+       if (!was_available_thread[id]) {
+               was_available_thread[id] = true;
+               num_was_available_threads++;
+       }
 }
 
 /**
@@ -98,6 +107,27 @@ bool Promise::thread_is_available(thread_id_t tid) const
        return available_thread[id];
 }
 
+bool Promise::thread_was_available(thread_id_t tid) const
+{
+       unsigned int id = id_to_int(tid);
+       if (id >= was_available_thread.size())
+               return false;
+       return was_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
 {
@@ -166,3 +196,9 @@ bool Promise::same_location(const ModelAction *act) const
 {
        return get_reader(0)->same_var(act);
 }
+
+/** @brief Get this Promise's index within the execution's promise array */
+int Promise::get_index() const
+{
+       return execution->get_promise_number(this);
+}