model: promises: eliminate threads when they "join"
[c11tester.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 <vector>
12
13 #include "modeltypes.h"
14 #include "mymemory.h"
15
16 class ModelAction;
17
18 struct future_value {
19         uint64_t value;
20         modelclock_t expiration;
21         thread_id_t tid;
22 };
23
24 class Promise {
25  public:
26         Promise(ModelAction *read, struct future_value fv);
27         ModelAction * get_action() const { return read; }
28         bool eliminate_thread(thread_id_t tid);
29         void add_thread(thread_id_t tid);
30         bool thread_is_available(thread_id_t tid) const;
31         bool has_failed() const;
32         void set_write(const ModelAction *act) { write = act; }
33         const ModelAction * get_write() const { return write; }
34         int get_num_available_threads() const { return num_available_threads; }
35         bool is_compatible(const ModelAction *act) const;
36         bool is_compatible_exclusive(const ModelAction *act) const;
37
38         modelclock_t get_expiration() const { return fv.expiration; }
39         uint64_t get_value() const { return fv.value; }
40         struct future_value get_fv() const { return fv; }
41
42         void print() const;
43
44         SNAPSHOTALLOC
45  private:
46         /** @brief Thread ID(s) for thread(s) that potentially can satisfy this
47          *  promise */
48         std::vector< bool, SnapshotAlloc<bool> > available_thread;
49
50         int num_available_threads;
51
52         const future_value fv;
53
54         /** @brief The action which reads a promised value */
55         ModelAction * const read;
56
57         const ModelAction *write;
58 };
59
60 #endif