nodestack/promise: move future_value struct, update headers
[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, uint64_t value, modelclock_t expiration) :
24         value(value), expiration(expiration), read(act), write(NULL)
25         {
26                 increment_threads(act->get_tid());
27         }
28         modelclock_t get_expiration() const { return expiration; }
29         ModelAction * get_action() const { return read; }
30         bool increment_threads(thread_id_t tid);
31
32         bool has_sync_thread(thread_id_t tid) {
33                 unsigned int id = id_to_int(tid);
34                 if (id >= synced_thread.size())
35                         return false;
36                 return synced_thread[id];
37         }
38
39         bool check_promise() const;
40         uint64_t get_value() const { return value; }
41         void set_write(const ModelAction *act) { write = act; }
42         const ModelAction * get_write() { return write; }
43
44         SNAPSHOTALLOC
45  private:
46         std::vector<bool> synced_thread;
47         const uint64_t value;
48         const modelclock_t expiration;
49         ModelAction * const read;
50         const ModelAction *write;
51 };
52
53 #endif