Fix a bug in memcpy, implement memset, and remove model_thread
[c11tester.git] / newfuzzer.h
1 #ifndef __NEWFUZZER_H__
2 #define __NEWFUZZER_H__
3
4 #include "fuzzer.h"
5 #include "classlist.h"
6 #include "mymemory.h"
7 #include "stl-model.h"
8 #include "predicate.h"
9
10 struct node_dist_info {
11         node_dist_info(thread_id_t tid, FuncNode * node, int distance) :
12                 tid(tid),
13                 target(node),
14                 dist(distance)
15         {}
16
17         thread_id_t tid;
18         FuncNode * target;
19         int dist;
20
21         SNAPSHOTALLOC
22 };
23
24 class NewFuzzer : public Fuzzer {
25 public:
26         NewFuzzer();
27         int selectWrite(ModelAction *read, SnapVector<ModelAction *>* rf_set);
28         bool has_paused_threads();
29         void notify_paused_thread(Thread * thread);
30
31         Thread * selectThread(int * threadlist, int numthreads);
32         Thread * selectNotify(simple_action_list_t * waiters);
33         bool shouldSleep(const ModelAction * sleep);
34         bool shouldWake(const ModelAction * sleep);
35
36         void register_engine(ModelChecker * model, ModelExecution * execution);
37         Predicate * get_selected_child_branch(thread_id_t tid);
38
39         SNAPSHOTALLOC
40 private:
41         ModelHistory * history;
42         ModelExecution * execution;
43
44         SnapVector<ModelAction *> thrd_last_read_act;
45         SnapVector<FuncInst *> thrd_last_func_inst;
46
47         SnapVector<Predicate *> available_branches_tmp_storage;
48         SnapVector<Predicate *> thrd_selected_child_branch;
49         SnapVector< SnapVector<ModelAction *> *> thrd_pruned_writes;
50
51         bool check_branch_inst(Predicate * curr_pred, FuncInst * read_inst, SnapVector<ModelAction *> * rf_set);
52         Predicate * selectBranch(thread_id_t tid, Predicate * curr_pred, FuncInst * read_inst);
53         bool prune_writes(thread_id_t tid, Predicate * pred, SnapVector<ModelAction *> * rf_set);
54         int choose_branch_index(SnapVector<Predicate *> * branches);
55
56         /* The set of Threads put to sleep by NewFuzzer because no writes in rf_set satisfies the selected predicate. Only used by selectWrite.
57          */
58         SnapVector<Thread *> paused_thread_list;        //-- (not in use)
59         HashTable<Thread *, int, uintptr_t, 0> paused_thread_table;     //--
60
61         SnapVector<struct node_dist_info> dist_info_vec;        //--
62
63         void conditional_sleep(Thread * thread);        //--
64         void wake_up_paused_threads(int * threadlist, int * numthreads);        //--
65
66         bool find_threads(ModelAction * pending_read);  //--
67 };
68
69 #endif  /* end of __NEWFUZZER_H__ */