changes
authorBrian Demsky <bdemsky@uci.edu>
Tue, 18 Sep 2012 22:46:29 +0000 (15:46 -0700)
committerBrian Demsky <bdemsky@uci.edu>
Tue, 18 Sep 2012 22:46:29 +0000 (15:46 -0700)
model.cc
model.h
nodestack.cc
nodestack.h
schedule.cc
schedule.h

index 007492286587d6a3ea9c619c191b30a3644b1007..72919c6d04b9e9aabed080f3b401aa6fcfa4e58a 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -33,7 +33,6 @@ ModelChecker::ModelChecker(struct model_params params) :
        lazy_sync_with_release(new HashTable<void *, std::list<ModelAction *>, uintptr_t, 4>()),
        thrd_last_action(new std::vector<ModelAction *>(1)),
        node_stack(new NodeStack()),
-       is_enabled(NULL),
        mo_graph(new CycleGraph()),
        failed_promise(false),
        too_many_reads(false),
@@ -53,8 +52,6 @@ ModelChecker::~ModelChecker()
        for (int i = 0; i < get_num_threads(); i++)
                delete thread_map->get(i);
        delete thread_map;
-       if (is_enabled)
-               free(is_enabled);
 
        delete obj_thrd_map;
        delete obj_map;
@@ -89,13 +86,7 @@ void ModelChecker::reset_to_initial_state()
 /** @returns a thread ID for a new Thread */
 thread_id_t ModelChecker::get_next_id()
 {
-       thread_id_t newid=priv->next_thread_id++;
-       bool * tmp=(bool *) malloc((newid+1)*sizeof(bool));
-       memcpy(tmp, is_enabled, newid*sizeof(bool));
-       tmp[newid]=true;
-       free(is_enabled);
-       is_enabled=tmp;
-       return newid;
+       return priv->next_thread_id++;
 }
 
 /** @returns the number of user threads created during this execution */
@@ -379,17 +370,17 @@ Thread * ModelChecker::check_current_action(ModelAction *curr)
                curr = tmp;
                compute_promises(curr);
        } else {
-               ModelAction *tmp = node_stack->explore_action(curr, NULL);
+               ModelAction *tmp = node_stack->explore_action(curr, scheduler->get_enabled());
                if (tmp) {
                        /* Discard duplicate ModelAction; use action from NodeStack */
                        /* First restore type and order in case of RMW operation */
                        if (curr->is_rmwr())
                                tmp->copy_typeandorder(curr);
-
+                       
                        /* If we have diverged, we need to reset the clock vector. */
                        if (diverge == NULL)
                                tmp->create_cv(get_parent_action(tmp->get_tid()));
-
+                       
                        delete curr;
                        curr = tmp;
                } else {
@@ -1342,25 +1333,23 @@ int ModelChecker::switch_to_master(ModelAction *act)
  * @return Returns true (success) if a step was taken and false otherwise.
  */
 bool ModelChecker::take_step() {
-       Thread *curr, *next;
-
        if (has_asserted())
                return false;
 
-       curr = thread_current();
+       Thread * curr = thread_current();
        if (curr) {
                if (curr->get_state() == THREAD_READY) {
                        ASSERT(priv->current_action);
 
                        priv->nextThread = check_current_action(priv->current_action);
                        priv->current_action = NULL;
-                       if (!curr->is_blocked() && !curr->is_complete())
-                               scheduler->add_thread(curr);
+                       if (curr->is_blocked() || curr->is_complete())
+                               scheduler->remove_thread(curr);
                } else {
                        ASSERT(false);
                }
        }
-       next = scheduler->next_thread(priv->nextThread);
+       Thread * next = scheduler->next_thread(priv->nextThread);
 
        /* Infeasible -> don't take any more steps */
        if (!isfeasible())
diff --git a/model.h b/model.h
index 54f302684fc092b7226fa5a1d0988b536962d236..4fc32c6db6c2800d2bdf705d7a8b256683968bab 100644 (file)
--- a/model.h
+++ b/model.h
@@ -177,8 +177,6 @@ private:
         * together for efficiency and maintainability. */
        struct model_snapshot_members *priv;
 
-       bool * is_enabled;
-
        /**
         * @brief The modification order graph
         *
index 69f0b5f513640f5861c6c3bf117c73fc440c7da6..2e170b9f35eb8e424db6949754bb32d8146a0ba2 100644 (file)
@@ -332,7 +332,7 @@ void NodeStack::print()
        printf("............................................\n");
 }
 
-ModelAction * NodeStack::explore_action(ModelAction *act, bool * enabled)
+ModelAction * NodeStack::explore_action(ModelAction *act, bool * is_enabled)
 {
        DBG();
 
@@ -347,7 +347,7 @@ ModelAction * NodeStack::explore_action(ModelAction *act, bool * enabled)
 
        /* Record action */
        get_head()->explore_child(act);
-       node_list.push_back(new Node(act, get_head(), model->get_num_threads(), enabled));
+       node_list.push_back(new Node(act, get_head(), model->get_num_threads()));
        total_nodes++;
        iter++;
        return NULL;
index 6cd8cfd30806c7463d6710e5251041bf4b64cd81..3262a569d0e5da24689c46c706752a3b718c9a69 100644 (file)
@@ -120,7 +120,7 @@ class NodeStack {
 public:
        NodeStack();
        ~NodeStack();
-       ModelAction * explore_action(ModelAction *act, bool * enabled);
+       ModelAction * explore_action(ModelAction *act, bool * is_enabled);
        Node * get_head();
        Node * get_next();
        void reset_execution();
index cbb4957a3e4a3865730679e8e816dfb51f636324..b19a5d304ce4d28b5e8ad7064c7b37aa18afaf17 100644 (file)
@@ -5,10 +5,26 @@
 
 /** Constructor */
 Scheduler::Scheduler() :
+       is_enabled(NULL),
+       enabled_len(0),
+       curr_thread_index(0),
        current(NULL)
 {
 }
 
+void Scheduler::set_enabled(Thread *t, bool enabled_status) {
+       int threadid=id_to_int(t->get_id());
+       if (threadid>=enabled_len) {
+               bool * new_enabled=(bool *)malloc(sizeof(bool)*(threadid+1));
+               memcpy(new_enabled, is_enabled, enabled_len*sizeof(bool));
+               memset(&new_enabled[enabled_len], 0, (threadid+1-enabled_len)*sizeof(bool));
+               free(is_enabled);
+               is_enabled=new_enabled;
+               enabled_len=threadid+1;
+       }
+       is_enabled[threadid]=enabled_status;
+}
+
 /**
  * Add a Thread to the scheduler's ready list.
  * @param t The Thread to add
@@ -16,7 +32,7 @@ Scheduler::Scheduler() :
 void Scheduler::add_thread(Thread *t)
 {
        DEBUG("thread %d\n", t->get_id());
-       readyList.push_back(t);
+       set_enabled(t, true);
 }
 
 /**
@@ -27,8 +43,7 @@ void Scheduler::remove_thread(Thread *t)
 {
        if (current == t)
                current = NULL;
-       else
-               readyList.remove(t);
+       set_enabled(t, false);
 }
 
 /**
@@ -38,7 +53,7 @@ void Scheduler::remove_thread(Thread *t)
  */
 void Scheduler::sleep(Thread *t)
 {
-       remove_thread(t);
+       set_enabled(t, false);
        t->set_state(THREAD_BLOCKED);
 }
 
@@ -48,7 +63,7 @@ void Scheduler::sleep(Thread *t)
  */
 void Scheduler::wake(Thread *t)
 {
-       add_thread(t);
+       set_enabled(t, true);
        t->set_state(THREAD_READY);
 }
 
@@ -62,19 +77,22 @@ void Scheduler::wake(Thread *t)
  */
 Thread * Scheduler::next_thread(Thread *t)
 {
-       if (t != NULL) {
-               current = t;
-               readyList.remove(t);
-       } else if (readyList.empty()) {
-               t = NULL;
-       } else {
-               t = readyList.front();
-               current = t;
-               readyList.pop_front();
+       if ( t == NULL ) {
+               int old_curr_thread = curr_thread_index;
+               while(true) {
+                       curr_thread_index = (curr_thread_index+1) % enabled_len;
+                       if (is_enabled[curr_thread_index]) {
+                               t = model->get_thread(int_to_id(curr_thread_index));
+                               break;
+                       }
+                       if (curr_thread_index == old_curr_thread) {
+                               print();
+                               return NULL;
+                       }
+               }
        }
-
+       current = t;
        print();
-
        return t;
 }
 
@@ -96,9 +114,4 @@ void Scheduler::print() const
                DEBUG("Current thread: %d\n", current->get_id());
        else
                DEBUG("No current thread\n");
-       DEBUG("Num. threads in ready list: %zu\n", readyList.size());
-
-       std::list<Thread *, MyAlloc< Thread * > >::const_iterator it;
-       for (it = readyList.begin(); it != readyList.end(); it++)
-               DEBUG("In ready list: thread %d\n", (*it)->get_id());
 }
index a7483e02340942cf773ea7a69c890d72b384f69a..fb4d082adc2dbe220baf49d8347fc70fe6c0d560 100644 (file)
@@ -23,11 +23,15 @@ public:
        Thread * next_thread(Thread *t);
        Thread * get_current_thread() const;
        void print() const;
+       bool * get_enabled() { return is_enabled; };
 
        SNAPSHOTALLOC
 private:
        /** The list of available Threads that are not currently running */
-       std::list<Thread *> readyList;
+       bool * is_enabled;
+       int enabled_len;
+       int curr_thread_index;
+       void set_enabled(Thread *t, bool enabled_status);
 
        /** The currently-running Thread */
        Thread *current;