add a new class 'ModelHistory'
[c11tester.git] / history.cc
1 #include <inttypes.h>
2 #include "history.h"
3 #include "action.h"
4
5 ModelHistory::ModelHistory() :
6         func_id(1), /* function id starts with 1 */
7         func_map(),
8         func_history(),
9         work_list()
10 {}
11
12 void ModelHistory::enter_function(const uint32_t func_id, thread_id_t tid)
13 {
14         if ( !work_list.contains(tid) ) {
15                 // This thread has not been pushed to work_list
16                 SnapList<uint32_t> * func_list = new SnapList<uint32_t>();
17                 func_list->push_back(func_id);
18                 work_list.put(tid, func_list);
19         } else {
20                 SnapList<uint32_t> * func_list = work_list.get(tid);
21                 func_list->push_back(func_id);
22         }
23 }
24
25 void ModelHistory::exit_function(const uint32_t func_id, thread_id_t tid)
26 {
27         SnapList<uint32_t> * func_list = work_list.get(tid);
28         uint32_t last_func_id = func_list->back();
29
30         if (last_func_id == func_id) {
31                 func_list->pop_back();
32         } else {
33                 model_print("trying to exit with a wrong function id\n");
34                 model_print("--- last_func: %d, func_id: %d\n", last_func_id, func_id);
35         }
36 }