1 #define __STDC_FORMAT_MACROS
9 * Eliminate a thread which no longer can satisfy this promise. Once all
10 * enabled threads have been eliminated, this promise is unresolvable.
12 * @param tid The thread ID of the thread to eliminate
13 * @return True, if this elimination has invalidated the promise; false
16 bool Promise::eliminate_thread(thread_id_t tid)
18 unsigned int id = id_to_int(tid);
19 if (!thread_is_available(tid))
22 available_thread[id] = false;
23 num_available_threads--;
28 * Add a thread which may resolve this promise
30 * @param tid The thread ID
32 void Promise::add_thread(thread_id_t tid)
34 unsigned int id = id_to_int(tid);
35 if (id >= available_thread.size())
36 available_thread.resize(id + 1, false);
37 if (!available_thread[id]) {
38 available_thread[id] = true;
39 num_available_threads++;
44 * Check if a thread is available for resolving this promise. That is, the
45 * thread must have been previously marked for resolving this promise, and it
46 * cannot have been eliminated due to synchronization, etc.
48 * @param tid Thread ID of the thread to check
49 * @return True if the thread is available; false otherwise
51 bool Promise::thread_is_available(thread_id_t tid) const
53 unsigned int id = id_to_int(tid);
54 if (id >= available_thread.size())
56 return available_thread[id];
59 /** @brief Print debug info about the Promise */
60 void Promise::print() const
62 model_print("Promised value %#" PRIx64 ", read from thread %d, available threads to resolve: ", value, id_to_int(read->get_tid()));
63 for (unsigned int i = 0; i < available_thread.size(); i++)
64 if (available_thread[i])
65 model_print("[%d]", i);
70 * Check if this promise has failed. A promise can fail when all threads which
71 * could possibly satisfy the promise have been eliminated.
73 * @return True, if this promise has failed; false otherwise
75 bool Promise::has_failed() const
77 return num_available_threads == 0;
81 * @brief Check if an action's thread and location are compatible for resolving
83 * @param act The action to check against
84 * @return True if we are compatible; false otherwise
86 bool Promise::is_compatible(const ModelAction *act) const
88 return thread_is_available(act->get_tid()) && read->same_var(act);
92 * @brief Check if an action's thread and location are compatible for resolving
93 * this promise, and that the promise is thread-exclusive
94 * @param act The action to check against
95 * @return True if we are compatible and exclusive; false otherwise
97 bool Promise::is_compatible_exclusive(const ModelAction *act) const
99 return get_num_available_threads() == 1 && is_compatible(act);