if (prevfi) {
*fi=*prevfi;
}
- if (parent->enabled_array[i]) {
+ if (parent->enabled_array[i]==THREAD_ENABLED) {
fi->enabled_count++;
}
if (i==currtid) {
}
//Do window processing
if (prevfairness != NULL) {
- if (prevfairness -> parent->enabled_array[i])
+ if (prevfairness -> parent->enabled_array[i] == THREAD_ENABLED)
fi->enabled_count--;
if (i==prevtid) {
fi->turns--;
* Mark the appropriate backtracking information for exploring a thread choice.
* @param act The ModelAction to explore
*/
-void Node::explore_child(ModelAction *act, bool * is_enabled)
+void Node::explore_child(ModelAction *act, enabled_type_t * is_enabled)
{
if ( ! enabled_array )
- enabled_array=(bool *)model_malloc(sizeof(bool)*num_threads);
+ enabled_array=(enabled_type_t *)model_malloc(sizeof(enabled_type_t)*num_threads);
if (is_enabled != NULL)
- memcpy(enabled_array, is_enabled, sizeof(bool)*num_threads);
+ memcpy(enabled_array, is_enabled, sizeof(enabled_type_t)*num_threads);
else {
for(int i=0;i<num_threads;i++)
- enabled_array[i]=false;
+ enabled_array[i]=THREAD_DISABLED;
}
explore(act->get_tid());
bool Node::is_enabled(Thread *t)
{
int thread_id=id_to_int(t->get_id());
- return thread_id < num_threads && enabled_array[thread_id];
+ return thread_id < num_threads && (enabled_array[thread_id] == THREAD_ENABLED);
}
bool Node::is_enabled(thread_id_t tid)
{
int thread_id=id_to_int(tid);
- return thread_id < num_threads && enabled_array[thread_id];
+ return thread_id < num_threads && (enabled_array[thread_id] == THREAD_ENABLED);
}
bool Node::has_priority(thread_id_t tid)
/** Note: The is_enabled set contains what actions were enabled when
* act was chosen. */
-ModelAction * NodeStack::explore_action(ModelAction *act, bool * is_enabled)
+ModelAction * NodeStack::explore_action(ModelAction *act, enabled_type_t * is_enabled)
{
DBG();
#include "mymemory.h"
#include "modeltypes.h"
+#include "schedule.h"
class ModelAction;
class Thread;
/* return true = backtrack set is empty */
bool backtrack_empty();
- void explore_child(ModelAction *act, bool * is_enabled);
+ void explore_child(ModelAction *act, enabled_type_t * is_enabled);
/* return false = thread was already in backtrack */
bool set_backtrack(thread_id_t id);
thread_id_t get_next_backtrack();
std::vector< bool, ModelAlloc<bool> > backtrack;
std::vector< struct fairness_info, ModelAlloc< struct fairness_info> > fairness;
int numBacktracks;
- bool *enabled_array;
+ enabled_type_t *enabled_array;
/** The set of ModelActions that this the action at this Node may read
* from. Only meaningful if this Node represents a 'read' action. */
public:
NodeStack();
~NodeStack();
- ModelAction * explore_action(ModelAction *act, bool * is_enabled);
+ ModelAction * explore_action(ModelAction *act, enabled_type_t * is_enabled);
Node * get_head();
Node * get_next();
void reset_execution();
return false;
synced_thread[id]=true;
- bool * enabled=model->get_scheduler()->get_enabled();
+ enabled_type_t * enabled=model->get_scheduler()->get_enabled();
for(unsigned int i=0;i<model->get_num_threads();i++) {
- if (!synced_thread[id] && enabled[id])
+ if (!synced_thread[id] && (enabled[id] == THREAD_ENABLED))
return false;
}
return true;
{
}
-void Scheduler::set_enabled(Thread *t, bool enabled_status) {
+void Scheduler::set_enabled(Thread *t, enabled_type_t enabled_status) {
int threadid=id_to_int(t->get_id());
if (threadid>=enabled_len) {
- bool *new_enabled = (bool *)snapshot_malloc(sizeof(bool) * (threadid + 1));
- memset(&new_enabled[enabled_len], 0, (threadid+1-enabled_len)*sizeof(bool));
+ enabled_type_t *new_enabled = (enabled_type_t *)snapshot_malloc(sizeof(enabled_type_t) * (threadid + 1));
+ memset(&new_enabled[enabled_len], 0, (threadid+1-enabled_len)*sizeof(enabled_type_t));
if (is_enabled != NULL) {
- memcpy(new_enabled, is_enabled, enabled_len*sizeof(bool));
+ memcpy(new_enabled, is_enabled, enabled_len*sizeof(enabled_type_t));
snapshot_free(is_enabled);
}
is_enabled=new_enabled;
void Scheduler::add_thread(Thread *t)
{
DEBUG("thread %d\n", id_to_int(t->get_id()));
- set_enabled(t, true);
+ set_enabled(t, THREAD_ENABLED);
}
/**
{
if (current == t)
current = NULL;
- set_enabled(t, false);
+ set_enabled(t, THREAD_DISABLED);
}
/**
*/
void Scheduler::sleep(Thread *t)
{
- set_enabled(t, false);
+ set_enabled(t, THREAD_DISABLED);
t->set_state(THREAD_BLOCKED);
}
*/
void Scheduler::wake(Thread *t)
{
- set_enabled(t, true);
+ set_enabled(t, THREAD_DISABLED);
t->set_state(THREAD_READY);
}
/* Forward declaration */
class Thread;
+typedef enum enabled_type {
+ THREAD_DISABLED,
+ THREAD_ENABLED,
+ THREAD_SLEEP_SET
+} enabled_type_t;
+
/** @brief The Scheduler class performs the mechanics of Thread execution
* scheduling. */
class Scheduler {
Thread * next_thread(Thread *t);
Thread * get_current_thread() const;
void print() const;
- bool * get_enabled() { return is_enabled; };
+ enabled_type_t * get_enabled() { return is_enabled; };
SNAPSHOTALLOC
private:
/** The list of available Threads that are not currently running */
- bool * is_enabled;
+ enabled_type_t * is_enabled;
int enabled_len;
int curr_thread_index;
- void set_enabled(Thread *t, bool enabled_status);
+ void set_enabled(Thread *t, enabled_type_t enabled_status);
/** The currently-running Thread */
Thread *current;