schedule: add is_enabled() function
authorBrian Norris <banorris@uci.edu>
Sun, 7 Oct 2012 21:57:42 +0000 (14:57 -0700)
committerBrian Norris <banorris@uci.edu>
Sun, 7 Oct 2012 22:26:48 +0000 (15:26 -0700)
The release sequence functionality needs to check whether a Thread is
currently enabled (rather than finding this information in a particular
Node).

Also, rename the (private) 'is_enabled' field to avoid a name conflict.

schedule.cc
schedule.h

index a236bd0..cca60eb 100644 (file)
@@ -8,7 +8,7 @@
 
 /** Constructor */
 Scheduler::Scheduler() :
 
 /** Constructor */
 Scheduler::Scheduler() :
-       is_enabled(NULL),
+       enabled(NULL),
        enabled_len(0),
        curr_thread_index(0),
        current(NULL)
        enabled_len(0),
        curr_thread_index(0),
        current(NULL)
@@ -20,14 +20,25 @@ void Scheduler::set_enabled(Thread *t, enabled_type_t enabled_status) {
        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 (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;
        }
                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);
 }
 
 /**
 }
 
 /**
@@ -86,7 +97,7 @@ Thread * Scheduler::next_thread(Thread *t)
                int old_curr_thread = curr_thread_index;
                while(true) {
                        curr_thread_index = (curr_thread_index+1) % enabled_len;
                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;
                        }
                                t = model->get_thread(int_to_id(curr_thread_index));
                                break;
                        }
index 18936b6..3feddd9 100644 (file)
@@ -29,12 +29,13 @@ public:
        Thread * next_thread(Thread *t);
        Thread * get_current_thread() const;
        void print() const;
        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 */
 
        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);
        int enabled_len;
        int curr_thread_index;
        void set_enabled(Thread *t, enabled_type_t enabled_status);