mymemory, threads: add allocator specifically for Thread
[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
12 #include "modeltypes.h"
13 #include "mymemory.h"
14 #include "stl-model.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         bool add_reader(ModelAction *reader);
28         ModelAction * get_reader(unsigned int i) const;
29         unsigned int get_num_readers() const { return readers.size(); }
30         bool eliminate_thread(thread_id_t tid);
31         void add_thread(thread_id_t tid);
32         bool thread_is_available(thread_id_t tid) const;
33         bool has_failed() const;
34         void set_write(const ModelAction *act) { write = act; }
35         const ModelAction * get_write() const { return write; }
36         int get_num_available_threads() const { return num_available_threads; }
37         bool is_compatible(const ModelAction *act) const;
38         bool is_compatible_exclusive(const ModelAction *act) const;
39         bool same_value(const ModelAction *write) const;
40         bool same_location(const ModelAction *act) const;
41
42         modelclock_t get_expiration() const { return fv.expiration; }
43         uint64_t get_value() const { return fv.value; }
44         struct future_value get_fv() const { return fv; }
45
46         void print() const;
47
48         bool equals(const Promise *x) const { return this == x; }
49         bool equals(const ModelAction *x) const { return false; }
50
51         SNAPSHOTALLOC
52  private:
53         /** @brief Thread ID(s) for thread(s) that potentially can satisfy this
54          *  promise */
55         SnapVector<bool> available_thread;
56
57         int num_available_threads;
58
59         const future_value fv;
60
61         /** @brief The action(s) which read the promised future value */
62         SnapVector<ModelAction *> readers;
63
64         const ModelAction *write;
65 };
66
67 #endif