Author: chromatic
Date: Sat Aug  9 13:52:57 2008
New Revision: 30151

Modified:
   trunk/src/pmc/scheduler.pmc

Log:
[PMC] Fixed compiler warnings (use of uninitialized variables) and tided code.

Modified: trunk/src/pmc/scheduler.pmc
==============================================================================
--- trunk/src/pmc/scheduler.pmc (original)
+++ trunk/src/pmc/scheduler.pmc Sat Aug  9 13:52:57 2008
@@ -41,7 +41,7 @@
 
 =item C<void init()>
 
-Initialize a concurrency scheduler object.
+Initializes a concurrency scheduler object.
 
 =cut
 
@@ -68,6 +68,7 @@
         MUTEX_INIT(core_struct->msg_lock);
     }
 
+
 /*
 
 =item C<void init_pmc(PMC *data)>
@@ -82,30 +83,33 @@
 
 =back
 
+=cut
+
 */
 
     VTABLE void init_pmc(PMC *data) {
         PMC              *elem;
         Parrot_Scheduler *core_struct;
 
-        if (! VTABLE_isa(INTERP, data, CONST_STRING(INTERP, "Hash")))
+        if (!VTABLE_isa(INTERP, data, CONST_STRING(INTERP, "Hash")))
             Parrot_ex_throw_from_c_args(INTERP, NULL, 
EXCEPTION_INVALID_OPERATION,
                 "Scheduler initializer must be a Hash");
 
         SELF.init();
-        core_struct = PARROT_SCHEDULER(SELF);
 
-        elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, 
"id"));
+        core_struct = PARROT_SCHEDULER(SELF);
+        elem        = VTABLE_get_pmc_keyed_str(INTERP, data, 
CONST_STRING(INTERP, "id"));
 
-        if (! PMC_IS_NULL(elem))
-            core_struct->id      = VTABLE_get_integer(INTERP, elem);
+        if (!PMC_IS_NULL(elem))
+            core_struct->id = VTABLE_get_integer(INTERP, elem);
     }
 
+
 /*
 
 =item C<void push_pmc(PMC *value)>
 
-Insert a task into the task list, giving it a task ID one higher than the
+Inserts a task into the task list, giving it a task ID one higher than the
 current maximum, and a birthtime of the current time.
 
 =cut
@@ -114,26 +118,23 @@
 
     void push_pmc(PMC *task) {
         Parrot_Scheduler * const core_struct = PARROT_SCHEDULER(SELF);
-        STRING *task_id_str;
-        INTVAL new_tid;
+        STRING                  *task_id_str;
+        INTVAL                   new_tid;
 
         task = VTABLE_share_ro(INTERP, task);
         VTABLE_set_number_native(INTERP, task, Parrot_floatval_time());
 
-        new_tid = ++(core_struct->max_tid);
+        new_tid     = ++(core_struct->max_tid);
         VTABLE_set_integer_native(INTERP, task, new_tid);
         task_id_str = string_from_int(INTERP, new_tid);
 
-        VTABLE_set_pmc_keyed_str(INTERP, core_struct->task_list, task_id_str, 
task);
+        VTABLE_set_pmc_keyed_str(INTERP, core_struct->task_list,
+                                         task_id_str, task);
 
-
-        if (task->vtable->base_type == enum_class_Timer) {
+        if (task->vtable->base_type == enum_class_Timer)
             VTABLE_push_integer(INTERP, core_struct->wait_index, new_tid);
-        }
-        else {
+        else
             VTABLE_push_integer(INTERP, core_struct->task_index, new_tid);
-        }
-
 
         SCHEDULER_cache_valid_CLEAR(SELF);
 
@@ -141,12 +142,13 @@
             Parrot_cx_runloop_wake(core_struct->interp, SELF);
     }
 
+
 /*
 
 =item C<PMC *pop_pmc()>
 
-Retrieve the next task from the task list. If the task index is invalid,
-recalculate it before retrieving the next task.
+Retrieves the next task from the task list. If the task index is invalid,
+recalculates it before retrieving the next task.
 
 =cut
 
@@ -158,20 +160,24 @@
 
         /* Pull the next valid task off the task list, skipping expired and
          * deleted tasks. */
-        while (PMC_IS_NULL(task) && VTABLE_elements(INTERP, 
core_struct->task_index) > 0) {
+        while (PMC_IS_NULL(task)
+        &&     VTABLE_elements(INTERP, core_struct->task_index) > 0) {
             INTVAL tid = VTABLE_shift_integer(INTERP, core_struct->task_index);
+
             if (tid > 0)
-                task = VTABLE_get_pmc_keyed_int(INTERP, 
core_struct->task_list, tid);
+                task = VTABLE_get_pmc_keyed_int(INTERP,
+                            core_struct->task_list, tid);
         }
 
         return task;
     }
 
+
 /*
 
 =item C<INTVAL get_integer()>
 
-Retrieve the number of pending tasks in the scheduler's task list.
+Retrieves the number of pending tasks in the scheduler's task list.
 
 =cut
 
@@ -194,46 +200,48 @@
 */
 
     VTABLE void delete_keyed_int(INTVAL key) {
-        Parrot_Scheduler * core_struct = PARROT_SCHEDULER(SELF);
-        STRING *task_id_str = string_from_int(INTERP, key);
+        Parrot_Scheduler *core_struct = PARROT_SCHEDULER(SELF);
+        STRING           *task_id_str = string_from_int(INTERP, key);
         VTABLE_delete_keyed_str(INTERP, core_struct->task_list, task_id_str);
         SCHEDULER_cache_valid_CLEAR(SELF);
     }
 
+
 /*
 
 =item C<PMC *share_ro()>
 
-Set this PMC as shared.
+Sets this PMC as shared.
 
 =cut
 
 */
 
     VTABLE PMC *share_ro() {
-        PMC *shared_self;
-        Parrot_Scheduler *shared_struct;
+        PMC              *shared_self;
+        Parrot_Scheduler *sched;
 
         if (PObj_is_PMC_shared_TEST(SELF))
             return SELF;
 
-        shared_self = pt_shared_fixup(INTERP, SELF);
-        shared_struct = PARROT_SCHEDULER(shared_self);
+        shared_self       = pt_shared_fixup(INTERP, SELF);
+        sched             = PARROT_SCHEDULER(shared_self);
 
-        shared_struct->task_list  = pt_shared_fixup(INTERP, 
shared_struct->task_list);
-        shared_struct->task_index = pt_shared_fixup(INTERP, 
shared_struct->task_index);
-        shared_struct->wait_index = pt_shared_fixup(INTERP, 
shared_struct->wait_index);
-        shared_struct->handlers   = pt_shared_fixup(INTERP, 
shared_struct->handlers);
-        shared_struct->messages   = pt_shared_fixup(INTERP, 
shared_struct->messages);
+        sched->task_list  = pt_shared_fixup(INTERP, sched->task_list);
+        sched->task_index = pt_shared_fixup(INTERP, sched->task_index);
+        sched->wait_index = pt_shared_fixup(INTERP, sched->wait_index);
+        sched->handlers   = pt_shared_fixup(INTERP, sched->handlers);
+        sched->messages   = pt_shared_fixup(INTERP, sched->messages);
 
         return shared_self;
     }
 
+
 /*
 
 =item C<void destroy()>
 
-Free the scheduler's underlying struct.
+Frees the scheduler's underlying struct.
 
 =cut
 
@@ -244,11 +252,12 @@
         mem_sys_free(core_struct);
     }
 
+
 /*
 
 =item C<void mark()>
 
-Mark any referenced strings and PMCs.
+Marks any referenced strings and PMCs as live.
 
 =cut
 
@@ -258,25 +267,26 @@
             Parrot_Scheduler * const core_struct = PARROT_SCHEDULER(SELF);
 
             if (core_struct->task_list)
-                pobject_lives(interp, (PObj*)core_struct->task_list);
+                pobject_lives(interp, (PObj *)core_struct->task_list);
             if (core_struct->task_index)
-                pobject_lives(interp, (PObj*)core_struct->task_index);
+                pobject_lives(interp, (PObj *)core_struct->task_index);
             if (core_struct->wait_index)
-                pobject_lives(interp, (PObj*)core_struct->wait_index);
+                pobject_lives(interp, (PObj *)core_struct->wait_index);
             if (core_struct->handlers)
-                pobject_lives(interp, (PObj*)core_struct->handlers);
+                pobject_lives(interp, (PObj *)core_struct->handlers);
             if (core_struct->messages)
-                pobject_lives(interp, (PObj*)core_struct->messages);
+                pobject_lives(interp, (PObj *)core_struct->messages);
         }
     }
 
+
 /*
 
 =item C<void visit(visit_info *info)>
 
-This is used by freeze/thaw to visit the contents of the scheduler.
+Visits the contents of the scheduler (used by freeze/thaw).
 
-C<*info> is the visit info, (see F<include/parrot/pmc_freeze.h>).
+C<*info> is the visit info (see F<include/parrot/pmc_freeze.h>).
 
 =cut
 
@@ -297,11 +307,12 @@
         (info->visit_pmc_now)(INTERP, *pos, info);
     }
 
+
 /*
 
 =item C<void freeze(visit_info *info)>
 
-Used to archive the scheduler.
+Archives the scheduler.
 
 =cut
 
@@ -318,11 +329,12 @@
         VTABLE_push_integer(INTERP, io, core_struct->max_tid);
     }
 
+
 /*
 
 =item C<void thaw(visit_info *info)>
 
-Used to unarchive the scheduler.
+Unarchives the scheduler.
 
 =cut
 
@@ -347,11 +359,12 @@
         PARROT_SCHEDULER(SELF)->max_tid = max_tid;
     }
 
+
 /*
 
 =item C<void thawfinish(visit_info *info)>
 
-Called after the scheduler has been thawed.
+Finishes thawing the scheduler.
 
 =cut
 
@@ -361,6 +374,7 @@
         Parrot_cx_refresh_task_list(INTERP, SELF);
     }
 
+
 /*
 
 =back
@@ -377,48 +391,51 @@
 
 =item C<METHOD add_handler(PMC *handler)>
 
-Add a handler to the scheduler.
+Adds a handler to the scheduler.
 
 =cut
 
 */
 
     METHOD add_handler(PMC *handler) {
-        Parrot_Scheduler * core_struct = PARROT_SCHEDULER(SELF);
+        Parrot_Scheduler *core_struct = PARROT_SCHEDULER(SELF);
         VTABLE_unshift_pmc(INTERP, core_struct->handlers, handler);
     }
 
+
 /*
 
-=item C<METHOD delete_handler(STRING *type :optional, INTVAL got_type 
:opt_flag)>
+=item C<METHOD delete_handler(STRING *type :optional, INTVAL have_type 
:opt_flag)>
 
-Delete a handler from the scheduler.
+Deletes a handler from the scheduler.
 
 =cut
 
 */
 
-    METHOD delete_handler(STRING *type :optional, INTVAL got_type :opt_flag) {
-        PMC *handlers;
-        INTVAL elements, index;
+    METHOD delete_handler(STRING *type :optional, INTVAL have_type :opt_flag) {
+        PMC    *handlers;
+        INTVAL  elements, index;
+        STRING *except_str = CONST_STRING(INTERP, "exception");
+        STRING *event_str  = CONST_STRING(INTERP, "event");
 
         GET_ATTR_handlers(INTERP, SELF, handlers);
         elements = VTABLE_elements(INTERP, handlers);
 
-        if (!got_type)
+        if (!have_type)
             VTABLE_shift_pmc(INTERP, handlers);
 
         /* Loop from newest handler to oldest handler. */
         for (index = 0; index < elements; ++index) {
             PMC *handler = VTABLE_get_pmc_keyed_int(INTERP, handlers, index);
             if (!PMC_IS_NULL(handler)) {
-                if (string_equal(INTERP, type, CONST_STRING(INTERP, 
"exception")) == 0
-                            && handler->vtable->base_type == 
enum_class_ExceptionHandler) {
+                if (string_equal(INTERP, type, except_str) == 0
+                &&  handler->vtable->base_type == enum_class_ExceptionHandler) 
{
                     VTABLE_set_pmc_keyed_int(INTERP, handlers, index, PMCNULL);
                     RETURN(void);
                 }
-                else if (string_equal(INTERP, type, CONST_STRING(INTERP, 
"event")) == 0
-                            && handler->vtable->base_type == 
enum_class_EventHandler) {
+                else if (string_equal(INTERP, type, event_str) == 0
+                     && handler->vtable->base_type == enum_class_EventHandler) 
{
                     VTABLE_set_pmc_keyed_int(INTERP, handlers, index, PMCNULL);
                     RETURN(void);
                }
@@ -429,11 +446,12 @@
             "No handler to delete.");
     }
 
+
 /*
 
 =item C<METHOD find_handler(PMC *task)>
 
-Search for a handler for the given task. If no handler is found, return
+Searchs for a handler for the given task. If no handler is found, returns
 PMCNULL.
 
 =cut
@@ -445,8 +463,8 @@
 
         /* Exceptions store the handler iterator for rethrow, other kinds of
          * tasks don't (though they could). */
-        if (task->vtable->base_type == enum_class_Exception &&
-                VTABLE_get_integer_keyed_str(interp, task,
+        if (task->vtable->base_type == enum_class_Exception
+        &&  VTABLE_get_integer_keyed_str(interp, task,
                     CONST_STRING(interp, "handled")) == -1) {
             iter = VTABLE_get_attr_str(interp, task,
                     CONST_STRING(interp, "handler_iter"));
@@ -483,42 +501,44 @@
 
 /*
 
-=item C<METHOD count_handlers(STRING *type :optional, INTVAL got_type 
:opt_flag)>
+=item C<METHOD count_handlers(STRING *type :optional, INTVAL have_type 
:opt_flag)>
 
-Return the number of handlers currently held by the scheduler. If a type
-argument is passed, only count handlers of that type (C<event>, C<exception>).
-If no type argument is passed, count all handlers.
+Returns the number of handlers currently held by the scheduler. If a type
+argument is passed, only counts handlers of that type (C<event>, C<exception>).
+If no type argument is passed, counts all handlers.
 
 =cut
 
 */
 
-    METHOD count_handlers(STRING *type :optional, INTVAL got_type :opt_flag) {
-        PMC *handlers;
+    METHOD count_handlers(STRING *type :optional, INTVAL have_type :opt_flag) {
+        /* avoid uninitialized value warning */
+        PMC   *handlers = NULL;
         INTVAL elements = VTABLE_elements(INTERP, handlers);
-        INTVAL index, count;
+        INTVAL count    = 0;
+        INTVAL index;
 
         GET_ATTR_handlers(INTERP, SELF, handlers);
 
-        if (!got_type)
-                RETURN(INTVAL elements);
+        if (!have_type)
+            RETURN(INTVAL elements);
 
         for (index = 0; index < elements; ++index) {
-            PMC *handler = VTABLE_get_pmc_keyed_int(INTERP, handlers, index);
+            PMC    *handler   = VTABLE_get_pmc_keyed_int(INTERP, handlers, 
index);
+            STRING *exception = CONST_STRING(INTERP, "exception");
+            STRING *event     = CONST_STRING(INTERP, "event");
+
             if (!PMC_IS_NULL(handler)) {
-                    if (string_equal(INTERP, type, CONST_STRING(INTERP, 
"exception")) == 0
-                                    && handler->vtable->base_type == 
enum_class_ExceptionHandler)
-                        count++;
-                    else if (string_equal(INTERP, type, CONST_STRING(INTERP, 
"event")) == 0
-                                    && handler->vtable->base_type == 
enum_class_EventHandler)
+                if (((string_equal(INTERP, type, exception) == 0)
+                &&   handler->vtable->base_type == enum_class_ExceptionHandler)
+                || ((string_equal(INTERP, type, event) == 0)
+                &&  handler->vtable->base_type == enum_class_EventHandler))
                         count++;
             }
         }
 
         RETURN(INTVAL count);
     }
-
-
 }
 
 /*

Reply via email to