promise: rename check_promise() -> has_failed()
[model-checker.git] / promise.cc
index 59fb9ee43115cd81ed60b2487ffbb563e90bd6da..7b110020cd869514c0f958055fea357f9f3c42ba 100644 (file)
@@ -2,31 +2,38 @@
 #include "model.h"
 #include "schedule.h"
 
-bool Promise::increment_threads(thread_id_t tid) { 
-       unsigned int id=id_to_int(tid); 
-       if ( id >= synced_thread.size() ) {
-               synced_thread.resize(id+1, false);
-       }
+/**
+ * Eliminate a thread which no longer can satisfy this promise. Once all
+ * enabled threads have been eliminated, this promise is unresolvable.
+ *
+ * @param tid The thread ID of the thread to eliminate
+ * @return True, if this elimination has invalidated the promise; false
+ * otherwise
+ */
+bool Promise::eliminate_thread(thread_id_t tid)
+{
+       unsigned int id = id_to_int(tid);
+       if (id >= synced_thread.size())
+               synced_thread.resize(id + 1, false);
        if (synced_thread[id])
                return false;
-       
-       synced_thread[id]=true;
-       enabled_type_t * enabled=model->get_scheduler()->get_enabled();
-       unsigned int sync_size=synced_thread.size();
-       int promise_tid=id_to_int(read->get_tid());
-       for(unsigned int i=1;i<model->get_num_threads();i++) {
-               if ((i >= sync_size || !synced_thread[i]) && ( i != promise_tid ) && (enabled[i] != THREAD_DISABLED)) {
-                       return false;
-               }
-       }
-       return true;
+
+       synced_thread[id] = true;
+       return has_failed();
 }
 
-bool Promise::check_promise() {
-       enabled_type_t * enabled=model->get_scheduler()->get_enabled();
-       unsigned int sync_size=synced_thread.size();
-       for(unsigned int i=1;i<model->get_num_threads();i++) {
-               if ((i >= sync_size || !synced_thread[i]) && (enabled[i] != THREAD_DISABLED)) {
+/**
+ * Check if this promise has failed. A promise can fail when all threads which
+ * could possibly satisfy the promise have been eliminated.
+ *
+ * @return True, if this promise has failed; false otherwise
+ */
+bool Promise::has_failed() const
+{
+       unsigned int sync_size = synced_thread.size();
+       int promise_tid = id_to_int(read->get_tid());
+       for (unsigned int i = 1; i < model->get_num_threads(); i++) {
+               if ((i >= sync_size || !synced_thread[i]) && ((int)i != promise_tid) && model->is_enabled(int_to_id(i))) {
                        return false;
                }
        }