This is an automated email from Gerrit.

Peter Stuge (pe...@stuge.se) just uploaded a new patch set to Gerrit, which you 
can find at http://openocd.zylin.com/893

-- gerrit

commit 403cafb3c0f4cd3c9c65bfd45f18b924c5ef8bf3
Author: Peter Stuge <pe...@stuge.se>
Date:   Thu Oct 4 14:31:29 2012 +0200

    rtos: Rewrite rtos_create() for readability
    
    The new code is functionally equivalent to the old,
    the only difference is that the code is now readable.
    
    Change-Id: If38b87439e9de2303b220b3a7e3200ceaa8391da
    Signed-off-by: Peter Stuge <pe...@stuge.se>

diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c
index 524e1da..b23625b 100644
--- a/src/rtos/rtos.c
+++ b/src/rtos/rtos.c
@@ -52,78 +52,77 @@ int rtos_smp_init(struct target *target)
        return ERROR_TARGET_INIT_FAILED;
 }
 
+static int os_alloc(struct target *target, struct rtos_type *ostype)
+{
+       struct rtos *os = target->rtos = calloc(1, sizeof(struct rtos));
+
+       if (!os)
+               return JIM_ERR;
+
+       os->type = ostype;
+       os->current_threadid = -1;
+       os->current_thread = 0;
+       os->symbols = NULL;
+       os->target = target;
+
+       /* RTOS drivers can override the packet handler in _create(). */
+       os->gdb_thread_packet = rtos_thread_packet;
+
+       return JIM_OK;
+}
+
+static int os_alloc_create(struct target *target, struct rtos_type *ostype)
+{
+       int ret = os_alloc(target, ostype);
+
+       if (JIM_OK == ret)
+               target->rtos->type->create(target);
+
+       return ret;
+}
+
 int rtos_create(Jim_GetOptInfo *goi, struct target *target)
 {
-       int x;
        char *cp;
-       if (!goi->isconfigure) {
-               if (goi->argc != 0) {
-                       if (goi->argc != 0) {
-                               Jim_WrongNumArgs(goi->interp,
-                                       goi->argc, goi->argv,
-                                       "NO PARAMS");
-                               return JIM_ERR;
-                       }
+       struct Jim_Obj *res;
+       struct rtos_type *type;
 
-                       Jim_SetResultString(goi->interp,
-                               target_type_name(target), -1);
-               }
+       if (!goi->isconfigure && goi->argc != 0) {
+               Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "NO 
PARAMS");
+               return JIM_ERR;
        }
 
-       if (target->rtos)
-               free((void *)(target->rtos));
-                                               /*                      e = 
Jim_GetOpt_String(goi,
-                                                * &cp, NULL); */
-/*                     target->rtos = strdup(cp); */
+       if (target->rtos) {
+               if (target->rtos->symbols)
+                       free(target->rtos->symbols);
+               free(target->rtos);
+               target->rtos = NULL;
+       }
 
        Jim_GetOpt_String(goi, &cp, NULL);
-       /* now does target type exist */
 
        if (0 == strcmp(cp, "auto")) {
-               /* auto detection of RTOS */
+               /* Auto detect tries to look up all symbols for each RTOS,
+                * and runs the RTOS driver's _detect() function when GDB
+                * finds all symbols for any RTOS. See rtos_qsymbol(). */
                target->rtos_auto_detect = true;
-               x = 0;
-       } else {
 
-               for (x = 0; rtos_types[x]; x++) {
-                       if (0 == strcmp(cp, rtos_types[x]->name)) {
-                               /* found */
-                               break;
-                       }
-               }
-               if (rtos_types[x] == NULL) {
-                       Jim_SetResultFormatted(goi->interp, "Unknown rtos type 
%s, try one of ",
-                               cp);
-                       for (x = 0; rtos_types[x]; x++) {
-                               if (rtos_types[x + 1]) {
-                                       Jim_AppendStrings(goi->interp,
-                                               Jim_GetResult(goi->interp),
-                                               rtos_types[x]->name,
-                                               ", ", NULL);
-                               } else {
-                                       Jim_AppendStrings(goi->interp,
-                                               Jim_GetResult(goi->interp),
-                                               " or ",
-                                               rtos_types[x]->name, NULL);
-                               }
-                       }
-                       return JIM_ERR;
-               }
+               /* rtos_qsymbol() will iterate over all RTOSes. Allocate
+                * target->rtos here, and set it to the first RTOS type. */
+               return os_alloc(target, rtos_types[0]);
        }
-       /* Create it */
-       target->rtos = calloc(1, sizeof(struct rtos));
-       target->rtos->type = rtos_types[x];
-       target->rtos->current_threadid = -1;
-       target->rtos->current_thread = 0;
-       target->rtos->symbols = NULL;
-       target->rtos->target = target;
-       /* put default thread handler in linux usecase it is overloaded*/
-       target->rtos->gdb_thread_packet = rtos_thread_packet;
-
-       if (0 != strcmp(cp, "auto"))
-               target->rtos->type->create(target);
 
-       return JIM_OK;
+       for (type = rtos_types[0]; type; type++)
+               if (0 == strcmp(cp, type->name))
+                       return os_alloc_create(target, type);
+
+       Jim_SetResultFormatted(goi->interp, "Unknown RTOS type %s, try one of: 
", cp);
+       res = Jim_GetResult(goi->interp);
+       for (type = rtos_types[0]; type; type++)
+               Jim_AppendStrings(goi->interp, res, type->name, ", ", NULL);
+       Jim_AppendStrings(goi->interp, res, " or auto", NULL);
+
+       return JIM_ERR;
 }
 
 int gdb_thread_packet(struct connection *connection, char *packet, int 
packet_size)

-- 

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to