promise: rename has_sync_thread() -> thread_is_eliminated()
[model-checker.git] / promise.h
1 /** @file promise.h
2  *
3  *  @brief Promise class --- tracks future obligations for execution
4  *  related to weakly ordered writes.
5  */
6
7 #ifndef __PROMISE_H__
8 #define __PROMISE_H__
9
10 #include <inttypes.h>
11 #include "threads-model.h"
12
13 #include "model.h"
14 #include "modeltypes.h"
15
16 struct future_value {
17         uint64_t value;
18         modelclock_t expiration;
19 };
20
21 class Promise {
22  public:
23         Promise(ModelAction *act, struct future_value fv) :
24                 value(fv.value),
25                 expiration(fv.expiration),
26                 read(act),
27                 write(NULL)
28         {
29                 eliminate_thread(act->get_tid());
30         }
31         modelclock_t get_expiration() const { return expiration; }
32         ModelAction * get_action() const { return read; }
33         bool eliminate_thread(thread_id_t tid);
34
35         /**
36          * Check if a thread has already been eliminated from resolving this
37          * promise
38          * @param tid Thread ID of the thread to check
39          * @return True if the thread is already eliminated; false otherwise
40          */
41         bool thread_is_eliminated(thread_id_t tid) const
42         {
43                 unsigned int id = id_to_int(tid);
44                 if (id >= eliminated_thread.size())
45                         return false;
46                 return eliminated_thread[id];
47         }
48
49         bool has_failed() const;
50         uint64_t get_value() const { return value; }
51         void set_write(const ModelAction *act) { write = act; }
52         const ModelAction * get_write() { return write; }
53
54         SNAPSHOTALLOC
55  private:
56         std::vector<bool> eliminated_thread;
57         const uint64_t value;
58         const modelclock_t expiration;
59         ModelAction * const read;
60         const ModelAction *write;
61 };
62
63 #endif