Makefile/malloc: don't warn for self-assign
[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
15 class Promise {
16  public:
17  Promise(ModelAction *act, uint64_t value, modelclock_t expiration) :
18         value(value), expiration(expiration), read(act), write(NULL)
19         { 
20                 increment_threads(act->get_tid());
21         }
22         modelclock_t get_expiration() const {return expiration;}
23         ModelAction * get_action() const { return read; }
24         bool increment_threads(thread_id_t tid);
25
26         bool has_sync_thread(thread_id_t tid) { 
27                 unsigned int id=id_to_int(tid); 
28                 if (id>=synced_thread.size()) {
29                         return false;
30                 }
31                 return synced_thread[id];
32         }
33
34         uint64_t get_value() const { return value; }
35         void set_write(const ModelAction *act) { write = act; }
36         const ModelAction * get_write() { return write; }
37
38         SNAPSHOTALLOC
39  private:
40         std::vector<bool> synced_thread;
41         const uint64_t value;
42         const modelclock_t expiration;
43         ModelAction * const read;
44         const ModelAction * write;
45 };
46
47 #endif