model: fully utilize Promise nodes in CycleGraph
[model-checker.git] / promise.cc
index e3b8d65e48d7c542bcf7e27da0473bb012a39057..ea5e7e635cf47df48a2ffc15fa0cd35d73b76025 100644 (file)
@@ -74,11 +74,25 @@ void Promise::print() const
  */
 bool Promise::has_failed() const
 {
-       for (unsigned int i = 0; i < available_thread.size(); i++) {
-               thread_id_t tid = int_to_id(i);
-               if (thread_is_available(tid) && model->is_enabled(tid))
-                       return false;
-       }
-       ASSERT(num_available_threads == 0);
-       return true;
+       return num_available_threads == 0;
+}
+
+/**
+ * @param write A store which could satisfy this Promise
+ * @return True if the store can satisfy this Promise; false otherwise
+ */
+bool Promise::is_compatible(const ModelAction *write) const
+{
+       return thread_is_available(write->get_tid()) && read->same_var(write);
+}
+
+/**
+ * @brief Check if a promise is compatible with a store and is exclusive to its
+ * thread
+ * @param write The store to check against
+ * @return True if we are compatible and exclusive; false otherwise
+ */
+bool Promise::is_compatible_exclusive(const ModelAction *write) const
+{
+       return get_num_available_threads() == 1 && is_compatible(write);
 }