/** Constructor */
Scheduler::Scheduler() :
- is_enabled(NULL),
+ enabled(NULL),
enabled_len(0),
curr_thread_index(0),
current(NULL)
if (threadid>=enabled_len) {
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(enabled_type_t));
- snapshot_free(is_enabled);
+ if (enabled != NULL) {
+ memcpy(new_enabled, enabled, enabled_len*sizeof(enabled_type_t));
+ snapshot_free(enabled);
}
- is_enabled=new_enabled;
+ enabled=new_enabled;
enabled_len=threadid+1;
}
- is_enabled[threadid]=enabled_status;
+ enabled[threadid]=enabled_status;
+}
+
+/**
+ * @brief Check if a Thread is currently enabled
+ * @param t The Thread to check
+ * @return True if the Thread is currently enabled
+ */
+bool Scheduler::is_enabled(Thread *t) const
+{
+ int id = id_to_int(t->get_id());
+ return (id >= enabled_len) ? false : (enabled[id] == THREAD_ENABLED);
}
/**
int old_curr_thread = curr_thread_index;
while(true) {
curr_thread_index = (curr_thread_index+1) % enabled_len;
- if (is_enabled[curr_thread_index]) {
+ if (enabled[curr_thread_index]) {
t = model->get_thread(int_to_id(curr_thread_index));
break;
}
Thread * next_thread(Thread *t);
Thread * get_current_thread() const;
void print() const;
- enabled_type_t * get_enabled() { return is_enabled; };
+ enabled_type_t * get_enabled() { return enabled; };
+ bool is_enabled(Thread *t) const;
SNAPSHOTALLOC
private:
/** The list of available Threads that are not currently running */
- enabled_type_t * is_enabled;
+ enabled_type_t *enabled;
int enabled_len;
int curr_thread_index;
void set_enabled(Thread *t, enabled_type_t enabled_status);