model: cosmetic improvements to resolve_promises()
[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         thread_id_t tid;
20 };
21
22 class Promise {
23  public:
24         Promise(ModelAction *read, struct future_value fv) :
25                 num_available_threads(0),
26                 value(fv.value),
27                 expiration(fv.expiration),
28                 read(read),
29                 write(NULL)
30         {
31                 add_thread(fv.tid);
32                 eliminate_thread(read->get_tid());
33         }
34         modelclock_t get_expiration() const { return expiration; }
35         ModelAction * get_action() const { return read; }
36         bool eliminate_thread(thread_id_t tid);
37         void add_thread(thread_id_t tid);
38         bool thread_is_available(thread_id_t tid) const;
39         bool has_failed() const;
40         uint64_t get_value() const { return value; }
41         void set_write(const ModelAction *act) { write = act; }
42         const ModelAction * get_write() const { return write; }
43         int get_num_available_threads() const { return num_available_threads; }
44         bool is_compatible(const ModelAction *write) const;
45         bool is_compatible_exclusive(const ModelAction *write) const;
46
47         void print() const;
48
49         SNAPSHOTALLOC
50  private:
51         /** @brief Thread ID(s) for thread(s) that potentially can satisfy this
52          *  promise */
53         std::vector< bool, SnapshotAlloc<bool> > available_thread;
54
55         int num_available_threads;
56
57         const uint64_t value;
58         const modelclock_t expiration;
59
60         /** @brief The action which reads a promised value */
61         ModelAction * const read;
62
63         const ModelAction *write;
64 };
65
66 #endif