IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8548


Ignore:
Timestamp:
Aug 23, 2006, 5:31:41 PM (20 years ago)
Author:
eugene
Message:

cleanup of timeouts and thread-safety issues, controller comms

Location:
trunk/Ohana/src/opihi/pantasks
Files:
1 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/pantasks/CheckPassword.c

    r7917 r8548  
    77
    88  VarConfig ("PASSWORD", "%s", PASSWORD);
    9 
     9  return (TRUE);
    1010}
    1111
  • trunk/Ohana/src/opihi/pantasks/ControllerOps.c

    r8184 r8548  
    290290    status = ReadtoIOBuffer (&buffer, stdout_fd[0]);
    291291    p = memstr (buffer.buffer, "CONNECTED", buffer.Nbuffer);
    292     usleep (10000);
     292    usleep (10000); // wait for controller to start up
    293293  }
    294294  if (status == 0) goto pipe_error;
     
    464464  result = waitpid (ControllerPID, &waitstatus, WNOHANG);
    465465  for (i = 0; (i < 10) && (result == 0); i++) {
    466     usleep (10000);  /* 10 ms is min */
     466    usleep (10000);  // wait for controller to exit
    467467    result = waitpid (ControllerPID, &waitstatus, WNOHANG);
    468468  }
  • trunk/Ohana/src/opihi/pantasks/InputQueue.c

    r7952 r8548  
    6565 
    6666  Nbytes = snprintf (&tmp, 0, "input %s", input);
    67   fprintf (stderr, "string len %d\n", Nbytes);
    68 
    6967  ALLOCATE (line, char, Nbytes + 1);
    70   fprintf (stderr, "allocated line\n");
    71 
    7268  snprintf (line, Nbytes + 1, "input %s", input);
    73  
    74   fprintf (stderr, "running command %s\n", line);
    7569
    7670  status = command (line, &outline, TRUE);
  • trunk/Ohana/src/opihi/pantasks/ListenClients.c

    r7940 r8548  
    6666  struct timeval timeout;
    6767  IOBuffer *outbuffer;
    68   IOBuffer testbuffer;
    6968
    7069  InitClients ();
  • trunk/Ohana/src/opihi/pantasks/LocalJob.c

    r7917 r8548  
    166166  result = 0;
    167167  for (i = 0; (i < 10) && (result == 0); i++) {
    168     usleep (10000);  /* 10 ms is min */
     168    usleep (10000);  // wait for job to exit
    169169    result = waitpid (job[0].pid, &waitstatus, WNOHANG);
    170170  }
     
    175175  result = 0;
    176176  for (i = 0; (i < 10) && (result == 0); i++) {
    177     usleep (10000);  /* 10 ms is min */
     177    usleep (10000);  // wait for job to exit
    178178    result = waitpid (job[0].pid, &waitstatus, WNOHANG);
    179179  }
  • trunk/Ohana/src/opihi/pantasks/Makefile

    r8129 r8548  
    2626
    2727single = \
    28 $(SDIR)/pantasks.$(ARCH).o
     28$(SDIR)/init.$(ARCH).o \
     29$(SDIR)/run.$(ARCH).o \
     30$(SDIR)/stop.$(ARCH).o \
     31$(SDIR)/pantasks.$(ARCH).o \
     32$(SDIR)/CheckSystem.$(ARCH).o
    2933
    3034funcs = \
    31 $(SDIR)/init.$(ARCH).o \
    3235$(SDIR)/CheckJobs.$(ARCH).o \
    33 $(SDIR)/CheckSystem.$(ARCH).o \
    3436$(SDIR)/CheckController.$(ARCH).o \
    3537$(SDIR)/CheckTasks.$(ARCH).o \
     
    4244
    4345cmds = \
    44 $(SDIR)/run.$(ARCH).o \
    45 $(SDIR)/stop.$(ARCH).o \
    4646$(SDIR)/pulse.$(ARCH).o \
    4747$(SDIR)/status.$(ARCH).o \
     
    5454$(SDIR)/controller_check.$(ARCH).o \
    5555$(SDIR)/controller_status.$(ARCH).o \
     56$(SDIR)/controller_run.$(ARCH).o \
    5657$(SDIR)/controller_output.$(ARCH).o \
    5758$(SDIR)/controller_pulse.$(ARCH).o \
  • trunk/Ohana/src/opihi/pantasks/TaskOps.c

    r8192 r8548  
    128128
    129129  int i, j;
    130   char *start, *stop
     130  char *start, *stop;
    131131  Task *task;
    132132
  • trunk/Ohana/src/opihi/pantasks/client_shell.c

    r7938 r8548  
    44int client_shell (int argc, char **argv) {
    55
    6   int i, Nbad, status, server;
     6  int Nbad, status;
    77  char *line, *prompt, *history;
    88  pid_t ppid;
  • trunk/Ohana/src/opihi/pantasks/controller.c

    r7917 r8548  
    44int controller_exit    PROTO((int, char **));
    55int controller_status  PROTO((int, char **));
     6int controller_run     PROTO((int, char **));
     7int controller_stop    PROTO((int, char **));
    68int controller_check   PROTO((int, char **));
    79int controller_output  PROTO((int, char **));
     
    1214  {"host",   controller_host,   "define host for controller"},
    1315  {"check",  controller_check,  "check controller host/job"},
     16  {"run",    controller_run,    "start controller operation"},
     17  {"stop",   controller_stop,   "stop controller (no disconnect)"},
    1418  {"status", controller_status, "check controller status"},
    1519  {"output", controller_output, "print controller output"},
     
    1923int controller (int argc, char **argv) {
    2024
    21   int status;
     25  int i, N, status;
    2226  CommandF *func;
    2327
     
    2529    gprint (GP_ERR, "USAGE: controller (command) ... \n");
    2630    return (FALSE);
     31  }
     32
     33  if (!strcasecmp (argv[1], "help")) {
     34    N = sizeof (controller_cmds) / sizeof (Command);
     35
     36    for (i = 0; i < N; i++) {
     37      gprint (GP_LOG, "%-15s %s\n", controller_cmds[i].name, controller_cmds[i].help);
     38    }
     39    return (TRUE);
    2740  }
    2841
  • trunk/Ohana/src/opihi/pantasks/controller_host.c

    r8184 r8548  
    2020  sprintf (command, "host %s %s", argv[1], argv[2]);
    2121  InitIOBuffer (&buffer, 0x100);
     22
     23  SerialThreadLock ();
    2224  status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer);
     25  SerialThreadUnlock ();
     26
    2327  if (status) gwrite (buffer.buffer, 1, buffer.Nbuffer, GP_LOG);
     28
    2429  FreeIOBuffer (&buffer);
    2530  return (TRUE);
  • trunk/Ohana/src/opihi/pantasks/controller_status.c

    r7917 r8548  
    1515  status = CheckControllerStatus ();
    1616  if (!status) {
    17     gprint (GP_LOG, "controller is not running\n");
     17    gprint (GP_LOG, "controller is not active\n");
    1818    return (TRUE);
    1919  }
    2020
     21
    2122  sprintf (command, "status");
    2223  InitIOBuffer (&buffer, 0x100);
     24
     25  SerialThreadLock ();
    2326  status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer);
     27  SerialThreadUnlock ();
     28
    2429  if (status) {
    2530    gwrite (buffer.buffer, 1, buffer.Nbuffer, GP_LOG);
    2631  } else {
    27     gprint (GP_LOG, "controller is down\n");
     32    gprint (GP_LOG, "controller is not communicating\n");
    2833  }
    2934  FreeIOBuffer (&buffer);
  • trunk/Ohana/src/opihi/pantasks/init_server.c

    r7960 r8548  
    88int task_macros     PROTO((int, char **));
    99int task_command    PROTO((int, char **));
     10int task_options    PROTO((int, char **));
    1011int task_periods    PROTO((int, char **));
    11 int run             PROTO((int, char **));
    12 int stop            PROTO((int, char **));
    1312int pulse           PROTO((int, char **));
    1413int status_server   PROTO((int, char **));
     
    1716int verbose         PROTO((int, char **));
    1817int version         PROTO((int, char **));
    19 int server         PROTO((int, char **));
     18int server          PROTO((int, char **));
    2019
    2120static Command cmds[] = { 
    22   {"controller", controller,   "controller commands"},
    23   {"task",       task,         "define a schedulable task"},
    24   {"host",       task_host,    "define host machine for a task"},
    25   {"nmax",       task_nmax,    "define maximum number of jobs for a task"},
    26   {"trange",     task_trange,  "define valid/invalid time periods for a task"},
    27   {"task.exit",  task_macros,  "define exit macros for a task"},
    28   {"task.exec",  task_macros,  "define pre-exec macro for a task"},
    29   {"command",    task_command, "define executed command for a task"},
    30   {"periods",    task_periods, "define time scales for a task"},
    31   {"run",        run,          "run the scheduler"},
    32   {"stop",       stop,         "stop the scheduler"},
    33   {"pulse",      pulse,        "set the scheduler update period"},
    34   {"server",     server,       "server-specific commands"},
     21  {"controller", controller,    "controller commands"},
     22  {"task",       task,          "define a schedulable task"},
     23  {"host",       task_host,     "define host machine for a task"},
     24  {"nmax",       task_nmax,     "define maximum number of jobs for a task"},
     25  {"trange",     task_trange,   "define valid/invalid time periods for a task"},
     26  {"task.exit",  task_macros,   "define exit macros for a task"},
     27  {"task.exec",  task_macros,   "define pre-exec macro for a task"},
     28  {"command",    task_command,  "define executed command for a task"},
     29  {"options",    task_options, "define optional variables associated with the job task"},
     30  {"periods",    task_periods,  "define time scales for a task"},
     31  {"pulse",      pulse,         "set the scheduler update period"},
     32  {"server",     server,        "server-specific commands"},
    3533  {"status",     status_server, "get system status"},
    36   {"kill",       kill_job,     "kill job"},
    37   {"delete",     delete_job,   "delete job"},
    38   {"version",    version,      "show version information"},
    39   {"verbose",    verbose,      "set/toggle verbose mode"},
     34  {"kill",       kill_job,      "kill job"},
     35  {"delete",     delete_job,    "delete job"},
     36  {"version",    version,       "show version information"},
     37  {"verbose",    verbose,       "set/toggle verbose mode"},
    4038};
    4139
  • trunk/Ohana/src/opihi/pantasks/pantasks_server.c

    r7952 r8548  
    1818  pthread_t clientsThread;
    1919  pthread_t tasksThread;
    20   pthread_t jobsThread;
     20  // pthread_t jobsThread;
    2121  pthread_t inputsThread;
    2222  pthread_t controllerThread;
     
    4848  pthread_create (&clientsThread,    NULL, &ListenClients,         NULL);
    4949  pthread_create (&tasksThread,      NULL, &CheckTasksThread,      NULL);
    50   pthread_create (&jobsThread,       NULL, &CheckJobsThread,       NULL);
     50  // pthread_create (&jobsThread,       NULL, &CheckJobsThread,            NULL);
    5151  pthread_create (&controllerThread, NULL, &CheckControllerThread, NULL);
    5252  pthread_create (&inputsThread,     NULL, &CheckInputsThread,     NULL);
  • trunk/Ohana/src/opihi/pantasks/server.c

    r7952 r8548  
    2727int server (int argc, char **argv) {
    2828
    29   int status;
     29  int i, N, status;
    3030  CommandF *func;
    3131
     
    3333    gprint (GP_ERR, "USAGE: server (command) ... \n");
    3434    return (FALSE);
     35  }
     36
     37  if (!strcasecmp (argv[1], "help")) {
     38    N = sizeof (server_cmds) / sizeof (Command);
     39
     40    for (i = 0; i < N; i++) {
     41      gprint (GP_LOG, "%-15s %s\n", server_cmds[i].name, server_cmds[i].help);
     42    }
     43    return (TRUE);
    3544  }
    3645
  • trunk/Ohana/src/opihi/pantasks/server_run.c

    r7952 r8548  
    99
    1010  CheckTasksSetState (TRUE);
     11  // CheckJobsSetState (TRUE);
     12  CheckControllerSetState (TRUE);
     13  CheckInputsSetState (TRUE);
    1114  return (TRUE);
    1215}
     
    2023
    2124  CheckTasksSetState (FALSE);
     25  // CheckJobsSetState (FALSE);
     26  CheckControllerSetState (FALSE);
     27  CheckInputsSetState (FALSE);
    2228  return (TRUE);
    2329}
  • trunk/Ohana/src/opihi/pantasks/server_threads.c

    r7960 r8548  
    1313}
    1414
     15/* the threaded version of pantasks does not worry about limiting the
     16   time spent in one of the test loops -- comms with the client are
     17   in a separate thread anyway...
     18*/
     19
     20int TestElapsedCheck () {
     21  return (FALSE);
     22}
     23
    1524/** things related to CheckTasks **/
    1625
     
    2433}
    2534
    26 void CheckTasksThread (void *data) {
     35void *CheckTasksThread (void *data) {
    2736
    2837  gprintInit ();  // each thread needs to init the printing system
     
    3140    // check for thread suspend
    3241    if (!CheckTasksRun) {
    33       usleep (500000);
     42      usleep (100000); // idle if thread action is suspended
    3443      continue;
    3544    }
     
    3847    SerialThreadLock ();
    3948    CheckTasks ();
     49    CheckJobs ();
    4050    SerialThreadUnlock ();
    4151    fprintf (stderr, "T");
    42     usleep (250000);
     52    usleep (10000); // allow other threads a chance to run
    4353  }
    4454}
    4555
     56# if 0
     57// XXX need to harvest jobs on the same thread as they were
     58// spawned.  for the moment, put CheckTasks and CheckJobs in
     59// a single thread.
    4660/** things related to CheckJobs **/
    4761
     
    5569}
    5670
    57 void CheckJobsThread (void *data) {
     71void *CheckJobsThread (void *data) {
    5872
    5973  gprintInit ();  // each thread needs to init the printing system
     
    6276    // check for thread suspend
    6377    if (!CheckJobsRun) {
    64       usleep (500000);
     78      usleep (100000); // idle if thread action is suspended
    6579      continue;
    6680    }
     
    7185    SerialThreadUnlock ();
    7286    fprintf (stderr, "J");
    73     usleep (250000);
     87    usleep (10000); // allow other threads a chance to run
    7488  }
    7589}
     90# endif
    7691
    7792/** things related to CheckController **/
     
    86101}
    87102
    88 void CheckControllerThread (void *data) {
     103void *CheckControllerThread (void *data) {
    89104
    90105  gprintInit ();  // each thread needs to init the printing system
     
    93108    // check for thread suspend
    94109    if (!CheckControllerRun) {
    95       usleep (500000);
     110      usleep (100000); // idle if thread action is suspended
    96111      continue;
    97112    }
     
    103118    SerialThreadUnlock ();
    104119    fprintf (stderr, "C");
    105     usleep (250000);
     120    usleep (10000); // allow other threads a chance to run
    106121  }
    107122}
     
    118133}
    119134
    120 void CheckInputsThread (void *data) {
     135void *CheckInputsThread (void *data) {
    121136
    122137  gprintInit ();  // each thread needs to init the printing system
     
    125140    // check for thread suspend
    126141    if (!CheckInputsRun) {
    127       usleep (500000);
     142      usleep (100000); // idle if thread action is suspended
    128143      continue;
    129144    }
     
    134149    SerialThreadUnlock ();
    135150    fprintf (stderr, "I");
    136     usleep (250000);
     151    usleep (10000); // allow other threads a chance to run
    137152  }
    138153}
  • trunk/Ohana/src/opihi/pantasks/status_server.c

    r7960 r8548  
    1010  }
    1111  if (CheckControllerGetState()) {
    12     gprint (GP_LOG, " Controller is running\n");
     12    gprint (GP_LOG, " Controller is active\n");
    1313  } else {
    14     gprint (GP_LOG, " Controller is stopped\n");
     14    gprint (GP_LOG, " Controller is not active\n");
    1515  }
    1616  ListTasks (FALSE);
Note: See TracChangeset for help on using the changeset viewer.