Revision: 76617
          http://sourceforge.net/p/brlcad/code/76617
Author:   starseeker
Date:     2020-07-31 20:44:27 +0000 (Fri, 31 Jul 2020)
Log Message:
-----------
Switch to using bu_ptbl instead of bu_list to hold the ged_subprocess instances

Modified Paths:
--------------
    brlcad/branches/bioh/include/ged/defines.h
    brlcad/branches/bioh/src/libged/ged.c
    brlcad/branches/bioh/src/libged/ged_util.c
    brlcad/branches/bioh/src/libged/process/process.c
    brlcad/branches/bioh/src/libged/rtabort/rtabort.c
    brlcad/branches/bioh/src/libged/rtcheck/rtcheck.c
    brlcad/branches/bioh/src/libged/rtwizard/rtwizard.c

Modified: brlcad/branches/bioh/include/ged/defines.h
===================================================================
--- brlcad/branches/bioh/include/ged/defines.h  2020-07-31 20:09:39 UTC (rev 
76616)
+++ brlcad/branches/bioh/include/ged/defines.h  2020-07-31 20:44:27 UTC (rev 
76617)
@@ -124,7 +124,6 @@
 
 
 struct ged_subprocess {
-    struct bu_list l;
     struct bu_process *p;
     void *chan;
     int aborted;
@@ -235,7 +234,7 @@
     int (*del)(struct ged *gedp, const char *name);
     int (*run)(struct ged *gedp, int ac, char *av[]);
 
-    struct ged_subprocess      gd_headSubprocess; /**< @brief  head of forked 
processes */
+    struct bu_ptbl             ged_subp; /**< @brief  forked sub-processes */
 
     /* Interface to LIBDM */
     void *ged_dmp;

Modified: brlcad/branches/bioh/src/libged/ged.c
===================================================================
--- brlcad/branches/bioh/src/libged/ged.c       2020-07-31 20:09:39 UTC (rev 
76616)
+++ brlcad/branches/bioh/src/libged/ged.c       2020-07-31 20:44:27 UTC (rev 
76617)
@@ -86,13 +86,16 @@
 
     /* Terminate any ged subprocesses */
     if (gedp != GED_NULL) {
-       struct ged_subprocess *rrp;
-       for (BU_LIST_FOR(rrp, ged_subprocess, &gedp->gd_headSubprocess.l)) {
+       for (size_t i = 0; i < BU_PTBL_LEN(&gedp->ged_subp); i++) {
+           struct ged_subprocess *rrp = (struct ged_subprocess 
*)BU_PTBL_GET(&gedp->ged_subp, i);
            if (!rrp->aborted) {
                bu_terminate(bu_process_pid(rrp->p));
                rrp->aborted = 1;
            }
+           bu_ptbl_rm(&gedp->ged_subp, (long *)rrp);
+           BU_PUT(rrp, struct ged_subprocess);
        }
+       bu_ptbl_reset(&gedp->ged_subp);
     }
 
     ged_free(gedp);
@@ -210,6 +213,8 @@
     bu_hash_destroy(gedp->ged_selections);
 
     BU_PUT(gedp->ged_cbs, struct ged_callback_state);
+
+    bu_ptbl_free(&gedp->ged_subp);
 }
 
 void
@@ -235,7 +240,7 @@
     BU_GET(gedp->ged_results, struct ged_results);
     (void)_ged_results_init(gedp->ged_results);
 
-    BU_LIST_INIT(&gedp->gd_headSubprocess.l);
+    BU_PTBL_INIT(&gedp->ged_subp);
 
     /* For now, we're keeping the string... will go once no one uses it */
     BU_GET(gedp->ged_result_str, struct bu_vls);

Modified: brlcad/branches/bioh/src/libged/ged_util.c
===================================================================
--- brlcad/branches/bioh/src/libged/ged_util.c  2020-07-31 20:09:39 UTC (rev 
76616)
+++ brlcad/branches/bioh/src/libged/ged_util.c  2020-07-31 20:44:27 UTC (rev 
76617)
@@ -1340,7 +1340,7 @@
            gedp->ged_gdp->gd_rtCmdNotify(aborted);
 
        /* free rrtp */
-       BU_LIST_DEQUEUE(&rrtp->l);
+       bu_ptbl_rm(&gedp->ged_subp, (long *)rrtp);
        BU_PUT(rrtp, struct ged_subprocess);
 
        return;
@@ -1443,8 +1443,7 @@
     bu_process_close(p, BU_PROCESS_STDIN);
 
     BU_GET(run_rtp, struct ged_subprocess);
-    BU_LIST_INIT(&run_rtp->l);
-    BU_LIST_APPEND(&gedp->gd_headSubprocess.l, &run_rtp->l);
+    bu_ptbl_ins(&gedp->ged_subp, (long *)run_rtp);
 
     run_rtp->p = p;
     run_rtp->aborted = 0;

Modified: brlcad/branches/bioh/src/libged/process/process.c
===================================================================
--- brlcad/branches/bioh/src/libged/process/process.c   2020-07-31 20:09:39 UTC 
(rev 76616)
+++ brlcad/branches/bioh/src/libged/process/process.c   2020-07-31 20:44:27 UTC 
(rev 76617)
@@ -57,7 +57,8 @@
     unsigned int longest_pid = 0;
 
     /* Find the largest pid we'll have to print */
-    for (BU_LIST_FOR(rrp, ged_subprocess, &gedp->gd_headSubprocess.l)) {
+    for (size_t i = 0; i < BU_PTBL_LEN(&gedp->ged_subp); i++) {
+       rrp = (struct ged_subprocess *)BU_PTBL_GET(&gedp->ged_subp, i);
        int pid = bu_process_pid(rrp->p);
        bu_vls_sprintf(&pid_str, "%d", pid);
        longest_pid = (bu_vls_strlen(&pid_str) > longest_pid) ? 
bu_vls_strlen(&pid_str) : longest_pid;
@@ -65,7 +66,8 @@
     bu_vls_free(&pid_str);
 
     /* For each process print a line */
-    for (BU_LIST_FOR(rrp, ged_subprocess, &gedp->gd_headSubprocess.l)) {
+    for (size_t i = 0; i < BU_PTBL_LEN(&gedp->ged_subp); i++) {
+       rrp = (struct ged_subprocess *)BU_PTBL_GET(&gedp->ged_subp, i);
        struct bu_vls pline = BU_VLS_INIT_ZERO;
        struct bu_vls cmdroot = BU_VLS_INIT_ZERO;
        const char * const *argv;
@@ -73,8 +75,8 @@
        int pid = bu_process_pid(rrp->p);
        (void)bu_path_component(&cmdroot, argv[0], BU_PATH_BASENAME_EXTLESS);
        bu_vls_sprintf(&pline, "%*d %s", longest_pid, pid, 
bu_vls_cstr(&cmdroot));
-       for (int i = 1; i < argc; i++) {
-           bu_vls_printf(&pline, " %s", argv[i]);
+       for (int j = 1; j < argc; j++) {
+           bu_vls_printf(&pline, " %s", argv[j]);
        }
        /* TODO - this should be intelligent based on current MGED/console 
terminal width... */
        bu_vls_trunc(&pline, 80);
@@ -104,12 +106,13 @@
      * more than once.  There may be more efficient ways to do this, but
      * it shouldn't matter unless the subprocess and/or argv lists get
      * extremely long. */
-    for (BU_LIST_FOR(rrp, ged_subprocess, &gedp->gd_headSubprocess.l)) {
+    for (size_t i = 0; i < BU_PTBL_LEN(&gedp->ged_subp); i++) {
+       rrp = (struct ged_subprocess *)BU_PTBL_GET(&gedp->ged_subp, i);
        int ppid = bu_process_pid(rrp->p);
-       for (int i = 0; i < argc; i++) {
+       for (int j = 0; j < argc; j++) {
            int pid;
-           if (bu_opt_int(NULL, 1, (const char **)&argv[i], (void *)&pid) < 0) 
{
-               bu_vls_printf(gedp->ged_result_str, "PID argument %s is not a 
valid process id.", argv[i]);
+           if (bu_opt_int(NULL, 1, (const char **)&argv[j], (void *)&pid) < 0) 
{
+               bu_vls_printf(gedp->ged_result_str, "PID argument %s is not a 
valid process id.", argv[j]);
                return GED_ERROR;
            }
            if (ppid == pid) {
@@ -133,13 +136,14 @@
      * to double-terminate a process if someone provides args that would
      * otherwise resolve that way - with this arrangement, each process
      * can get terminated at most once. */
-    for (BU_LIST_FOR(rrp, ged_subprocess, &gedp->gd_headSubprocess.l)) {
+    for (size_t i = 0; i < BU_PTBL_LEN(&gedp->ged_subp); i++) {
+       rrp = (struct ged_subprocess *)BU_PTBL_GET(&gedp->ged_subp, i);
        const char *cmd;
        int argcnt = bu_process_args(&cmd, NULL, rrp->p);
        bu_vls_trunc(&cmdroot, 0);
        if (argcnt > 0 && bu_path_component(&cmdroot, cmd, 
BU_PATH_BASENAME_EXTLESS)) {
-           for (int i = 0; i < argc; i++) {
-               if (!bu_path_match(argv[i], bu_vls_cstr(&cmdroot), 0)) {
+           for (int j = 0; j < argc; j++) {
+               if (!bu_path_match(argv[j], bu_vls_cstr(&cmdroot), 0)) {
                    bu_terminate(bu_process_pid(rrp->p));
                    rrp->aborted = 1;
                    /* terminated it, no need to check other args for

Modified: brlcad/branches/bioh/src/libged/rtabort/rtabort.c
===================================================================
--- brlcad/branches/bioh/src/libged/rtabort/rtabort.c   2020-07-31 20:09:39 UTC 
(rev 76616)
+++ brlcad/branches/bioh/src/libged/rtabort/rtabort.c   2020-07-31 20:44:27 UTC 
(rev 76617)
@@ -57,7 +57,8 @@
        return GED_ERROR;
     }
 
-    for (BU_LIST_FOR(rrp, ged_subprocess, &gedp->gd_headSubprocess.l)) {
+    for (size_t i = 0; i < BU_PTBL_LEN(&gedp->ged_subp); i++) {
+       rrp = (struct ged_subprocess *)BU_PTBL_GET(&gedp->ged_subp, i);
        const char *cmd;
        int argcnt = bu_process_args(&cmd, NULL, rrp->p);
        bu_vls_trunc(&cmdroot, 0);

Modified: brlcad/branches/bioh/src/libged/rtcheck/rtcheck.c
===================================================================
--- brlcad/branches/bioh/src/libged/rtcheck/rtcheck.c   2020-07-31 20:09:39 UTC 
(rev 76616)
+++ brlcad/branches/bioh/src/libged/rtcheck/rtcheck.c   2020-07-31 20:44:27 UTC 
(rev 76617)
@@ -68,7 +68,7 @@
        _ged_wait_status(gedp->ged_result_str, retcode);
     }
 
-    BU_LIST_DEQUEUE(&rrtp->l);
+    bu_ptbl_rm(&gedp->ged_subp, (long *)rrtp);
     BU_PUT(rrtp, struct ged_subprocess);
     BU_PUT(rtcp, struct ged_rtcheck);
 }
@@ -272,8 +272,7 @@
     if (gedp->ged_create_io_handler) {
        (*gedp->ged_create_io_handler)(rtcp->rrtp, BU_PROCESS_STDOUT, 
rtcheck_vector_handler, (void *)rtcp);
     }
-    BU_LIST_INIT(&rtcp->rrtp->l);
-    BU_LIST_APPEND(&gedp->gd_headSubprocess.l, &rtcp->rrtp->l);
+    bu_ptbl_ins(&gedp->ged_subp, (long *)rtcp->rrtp);
 
     if (gedp->ged_create_io_handler) {
        (*gedp->ged_create_io_handler)(rtcp->rrtp, BU_PROCESS_STDERR, 
rtcheck_output_handler, (void *)rtcp);

Modified: brlcad/branches/bioh/src/libged/rtwizard/rtwizard.c
===================================================================
--- brlcad/branches/bioh/src/libged/rtwizard/rtwizard.c 2020-07-31 20:09:39 UTC 
(rev 76616)
+++ brlcad/branches/bioh/src/libged/rtwizard/rtwizard.c 2020-07-31 20:44:27 UTC 
(rev 76617)
@@ -56,8 +56,7 @@
     }
 
     BU_GET(run_rtp, struct ged_subprocess);
-    BU_LIST_INIT(&run_rtp->l);
-    BU_LIST_APPEND(&gedp->gd_headSubprocess.l, &run_rtp->l);
+    bu_ptbl_ins(&gedp->ged_subp, (long *)run_rtp);
 
     run_rtp->p = p;
     run_rtp->aborted = 0;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to