schedule, threads: update comments, const's
authorBrian Norris <banorris@uci.edu>
Fri, 10 Aug 2012 21:43:19 +0000 (14:43 -0700)
committerBrian Norris <banorris@uci.edu>
Thu, 16 Aug 2012 17:30:25 +0000 (10:30 -0700)
schedule.cc
schedule.h
threads.cc

index 1791605b7c38842c37d11553c37f663c9dc88c38..8f7f1a98d8cc2833c812243cecaa284d375286ad 100644 (file)
@@ -3,17 +3,26 @@
 #include "common.h"
 #include "model.h"
 
+/** Constructor */
 Scheduler::Scheduler() :
        current(NULL)
 {
 }
 
+/**
+ * Add a Thread to the scheduler's ready list.
+ * @param t The Thread to add
+ */
 void Scheduler::add_thread(Thread *t)
 {
        DEBUG("thread %d\n", t->get_id());
        readyList.push_back(t);
 }
 
+/**
+ * Remove a given Thread from the scheduler.
+ * @param t The Thread to remove
+ */
 void Scheduler::remove_thread(Thread *t)
 {
        if (current == t)
@@ -22,7 +31,11 @@ void Scheduler::remove_thread(Thread *t)
                readyList.remove(t);
 }
 
-Thread * Scheduler::next_thread(void)
+/**
+ * Remove one Thread from the scheduler. This implementation performs FIFO.
+ * @return The next Thread to run
+ */
+Thread * Scheduler::next_thread()
 {
        Thread *t = model->schedule_next_thread();
 
@@ -42,11 +55,18 @@ Thread * Scheduler::next_thread(void)
        return t;
 }
 
-Thread * Scheduler::get_current_thread(void)
+/**
+ * @return The currently-running Thread
+ */
+Thread * Scheduler::get_current_thread() const
 {
        return current;
 }
 
+/**
+ * Print debugging information about the current state of the scheduler. Only
+ * prints something if debugging is enabled.
+ */
 void Scheduler::print()
 {
        if (current)
index cba4b11a6d597011910ceec3a55324d5edf136f4..68ef11106d080afddd6857a322e6d254501554a3 100644 (file)
@@ -18,13 +18,16 @@ public:
        Scheduler();
        void add_thread(Thread *t);
        void remove_thread(Thread *t);
-       Thread * next_thread(void);
-       Thread * get_current_thread(void);
+       Thread * next_thread();
+       Thread * get_current_thread() const;
        void print();
 
        SNAPSHOTALLOC
 private:
+       /** The list of available Threads that are not currently running */
        std::list<Thread *> readyList;
+
+       /** The currently-running Thread */
        Thread *current;
 };
 
index ad88ad3602188e3fdb4d2089347ae004b03cadda..7fa4281d36597db401dfb0b93da45f27f60a1ead 100644 (file)
@@ -22,7 +22,6 @@ static void stack_free(void *stack)
 }
 
 /** Return the currently executing thread. */
-
 Thread * thread_current(void)
 {
        ASSERT(model);
@@ -47,11 +46,11 @@ void thread_startup()
        curr_thread->start_routine(curr_thread->arg);
 }
 
-/** Create a thread context for a new thread so we can use
- *  setcontext/getcontext/swapcontext to swap it out.
- *  @return 0 on success.
+/**
+ * Create a thread context for a new thread so we can use
+ * setcontext/getcontext/swapcontext to swap it out.
+ * @return 0 on success; otherwise, non-zero error condition
  */
-
 int Thread::create_context()
 {
        int ret;
@@ -109,12 +108,12 @@ void Thread::complete()
        }
 }
 
-/** Create a new thread.
- *  Takes the following parameters:
- *  @param t The thread identifier of the newly created thread.
- *  @param func  The function that the thread will call.
- *  @param a The parameter to pass to this function. */
-
+/**
+ * Construct a new thread.
+ * @param t The thread identifier of the newly created thread.
+ * @param func The function that the thread will call.
+ * @param a The parameter to pass to this function.
+ */
 Thread::Thread(thrd_t *t, void (*func)(void *), void *a) :
        start_routine(func),
        arg(a),
@@ -134,14 +133,14 @@ Thread::Thread(thrd_t *t, void (*func)(void *), void *a) :
        parent = thread_current();
 }
 
+/** Destructor */
 Thread::~Thread()
 {
        complete();
        model->remove_thread(this);
 }
 
-/** Return the thread_id_t corresponding to this Thread object. */
-
+/** @return The thread_id_t corresponding to this Thread object. */
 thread_id_t Thread::get_id()
 {
        return id;