README: update text
[cdsspec-compiler.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
12 #include "modeltypes.h"
13 #include "mymemory.h"
14 #include "stl-model.h"
15
16 class ModelAction;
17 class ModelExecution;
18
19 struct future_value {
20         uint64_t value;
21         modelclock_t expiration;
22         thread_id_t tid;
23 };
24
25 class Promise {
26  public:
27         Promise(const ModelExecution *execution, ModelAction *read, struct future_value fv);
28         bool add_reader(ModelAction *reader);
29         ModelAction * get_reader(unsigned int i) const;
30         unsigned int get_num_readers() const { return readers.size(); }
31         bool eliminate_thread(thread_id_t tid);
32         void add_thread(thread_id_t tid);
33         bool thread_is_available(thread_id_t tid) const;
34         unsigned int max_available_thread_idx() const;
35         bool has_failed() const;
36         void set_write(const ModelAction *act) { write = act; }
37         const ModelAction * get_write() const { return write; }
38         int get_num_available_threads() const { return num_available_threads; }
39         bool is_compatible(const ModelAction *act) const;
40         bool is_compatible_exclusive(const ModelAction *act) const;
41         bool same_value(const ModelAction *write) const;
42         bool same_location(const ModelAction *act) const;
43
44         modelclock_t get_expiration() const { return fv.expiration; }
45         uint64_t get_value() const { return fv.value; }
46         struct future_value get_fv() const { return fv; }
47
48         int get_index() const;
49
50         void print() const;
51
52         bool equals(const Promise *x) const { return this == x; }
53         bool equals(const ModelAction *x) const { return false; }
54
55         SNAPSHOTALLOC
56  private:
57         /** @brief The execution which created this Promise */
58         const ModelExecution *execution;
59
60         /** @brief Thread ID(s) for thread(s) that potentially can satisfy this
61          *  promise */
62         SnapVector<bool> available_thread;
63
64         int num_available_threads;
65
66         const future_value fv;
67
68         /** @brief The action(s) which read the promised future value */
69         SnapVector<ModelAction *> readers;
70
71         const ModelAction *write;
72 };
73
74 #endif