promise: rename increment_threads() -> eliminate_thread()
[c11tester.git] / promise.cc
1 #include "promise.h"
2 #include "model.h"
3 #include "schedule.h"
4
5 /**
6  * Eliminate a thread which no longer can satisfy this promise. Once all
7  * enabled threads have been eliminated, this promise is unresolvable.
8  *
9  * @param tid The thread ID of the thread to eliminate
10  * @return True, if this elimination has invalidated the promise; false
11  * otherwise
12  */
13 bool Promise::eliminate_thread(thread_id_t tid)
14 {
15         unsigned int id = id_to_int(tid);
16         if (id >= synced_thread.size())
17                 synced_thread.resize(id + 1, false);
18         if (synced_thread[id])
19                 return false;
20
21         synced_thread[id] = true;
22         unsigned int sync_size = synced_thread.size();
23         int promise_tid = id_to_int(read->get_tid());
24         for (unsigned int i = 1; i < model->get_num_threads(); i++) {
25                 if ((i >= sync_size || !synced_thread[i]) && ((int)i != promise_tid) && model->is_enabled(int_to_id(i))) {
26                         return false;
27                 }
28         }
29         return true;
30 }
31
32 bool Promise::check_promise() const
33 {
34         unsigned int sync_size = synced_thread.size();
35         for (unsigned int i = 1; i < model->get_num_threads(); i++) {
36                 if ((i >= sync_size || !synced_thread[i]) && model->is_enabled(int_to_id(i))) {
37                         return false;
38                 }
39         }
40         return true;
41 }