model: make thread_map heap allocated
authorBrian Norris <banorris@uci.edu>
Sat, 26 May 2012 00:53:56 +0000 (17:53 -0700)
committerBrian Norris <banorris@uci.edu>
Sat, 26 May 2012 01:02:40 +0000 (18:02 -0700)
I want to snapshot this structure, so make it heap-allocated.

model.cc
model.h

index 62be08746db8ad95fe4aa09283c2f2034250a750..09ee4b4a91d07e2667738a0867782061ed97fb97 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -24,6 +24,7 @@ ModelChecker::ModelChecker()
        diverge(NULL),
        nextThread(THREAD_ID_T_NONE),
        action_trace(new action_list_t()),
+       thread_map(new std::map<int, class Thread *>),
        node_stack(new NodeStack()),
        next_backtrack(NULL)
 {
@@ -32,9 +33,9 @@ ModelChecker::ModelChecker()
 ModelChecker::~ModelChecker()
 {
        std::map<int, class Thread *>::iterator it;
-       for (it = thread_map.begin(); it != thread_map.end(); it++)
+       for (it = thread_map->begin(); it != thread_map->end(); it++)
                delete (*it).second;
-       thread_map.clear();
+       delete thread_map;
 
        delete action_trace;
 
@@ -46,9 +47,9 @@ void ModelChecker::reset_to_initial_state()
 {
        DEBUG("+++ Resetting to initial state +++\n");
        std::map<int, class Thread *>::iterator it;
-       for (it = thread_map.begin(); it != thread_map.end(); it++)
+       for (it = thread_map->begin(); it != thread_map->end(); it++)
                delete (*it).second;
-       thread_map.clear();
+       thread_map->clear();
        delete action_trace;
        action_trace = new action_list_t();
        node_stack->reset_execution();
@@ -75,7 +76,7 @@ Thread * ModelChecker::schedule_next_thread()
        Thread *t;
        if (nextThread == THREAD_ID_T_NONE)
                return NULL;
-       t = thread_map[id_to_int(nextThread)];
+       t = (*thread_map)[id_to_int(nextThread)];
 
        ASSERT(t != NULL);
 
@@ -248,7 +249,7 @@ void ModelChecker::print_list(action_list_t *list)
 
 int ModelChecker::add_thread(Thread *t)
 {
-       thread_map[id_to_int(t->get_id())] = t;
+       (*thread_map)[id_to_int(t->get_id())] = t;
        scheduler->add_thread(t);
        return 0;
 }
diff --git a/model.h b/model.h
index 9d2fd5a17f402babf0aeae888c00c6d2c0b75d46..57959b7c1609c838a7164ae0104eacd50c2ff1b7 100644 (file)
--- a/model.h
+++ b/model.h
@@ -34,7 +34,7 @@ public:
 
        int add_thread(Thread *t);
        void remove_thread(Thread *t);
-       Thread * get_thread(thread_id_t tid) { return thread_map[id_to_int(tid)]; }
+       Thread * get_thread(thread_id_t tid) { return (*thread_map)[id_to_int(tid)]; }
 
        thread_id_t get_next_id();
        int get_next_seq_num();
@@ -63,7 +63,7 @@ private:
 
        ucontext_t *system_context;
        action_list_t *action_trace;
-       std::map<int, class Thread *> thread_map;
+       std::map<int, class Thread *> *thread_map;
        class NodeStack *node_stack;
        ModelAction *next_backtrack;
 };