IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

cleanup of timeouts and thread-safety issues

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/pcontrol/StopHosts.c

    r8424 r8546  
    1717}
    1818
     19/* for use by shutdown: force machines which are up to go down
     20   wait for a little while for the client thread to take care
     21   of them
     22*/
     23   
    1924int DownHosts () {
    2025
     26  int i, Nobject, Nwait;
    2127  Stack *stack;
    2228  Host  *host;
    2329
     30  SetCheckPoint (); // ensure we can find the specified host
    2431  stack = GetHostStack (PCONTROL_HOST_IDLE);
    25   while ((host = PullStackByLocation (stack, STACK_BOTTOM)) != NULL) {
    26     StopHost (host);
    27     DownHost (host);
     32  Nobject = stack[0].Nobject;
     33  for (i = 0; i < Nobject; i++) {
     34    host = PullStackByLocation (stack, STACK_TOP);
     35    if (host == NULL) continue;
     36    host[0].markoff = TRUE;
     37    PutHost (host, PCONTROL_HOST_IDLE, STACK_BOTTOM);
    2838  }
    2939
    3040  stack = GetHostStack (PCONTROL_HOST_BUSY);
    31   while ((host = PullStackByLocation (stack, STACK_BOTTOM)) != NULL) {
    32     StopHost (host);
    33     DownHost (host);
     41  Nobject = stack[0].Nobject;
     42  for (i = 0; i < Nobject; i++) {
     43    host = PullStackByLocation (stack, STACK_TOP);
     44    if (host == NULL) continue;
     45    host[0].markoff = TRUE;
     46    PutHost (host, PCONTROL_HOST_IDLE, STACK_BOTTOM);
     47  }
     48  ClearCheckPoint ();
     49
     50  Nwait = 0;
     51  stack = GetHostStack (PCONTROL_HOST_IDLE);
     52  gprint (GP_ERR, "waiting for clients to exit");
     53  while ((Nwait < 15) && stack[0].Nobject) {
     54    gprint (GP_ERR, ".");
     55    usleep (100000); // wait for clients to exit
     56    Nwait++;
     57  }
     58  gprint (GP_ERR, "\n");
     59  if (stack[0].Nobject) {
     60    gprint (GP_ERR, "trouble shutting down all pclient instances: %d still alive\n", stack[0].Nobject);
     61  } else {
     62    gprint (GP_ERR, "done\n");
    3463  }
    3564  return (TRUE);
     
    6998  int i, result, waitstatus;
    7099
    71   gprint (GP_ERR, "harvesting within thread %d\n", pthread_self());
    72   gprint (GP_ERR, "child process %d is down, wait for exit status\n", pid);
     100  // gprint (GP_ERR, "harvesting within thread %d\n", pthread_self());
     101  // gprint (GP_ERR, "child process %d is down, wait for exit status\n", pid);
    73102 
    74103  // Loop a few times waiting for child to exit
     
    76105    result = waitpid (pid, &waitstatus, WNOHANG);
    77106    if ((result == -1) && (errno == ECHILD)) {
    78       usleep (10000);
     107      usleep (10000); // wait for child to exit
    79108      continue;
    80109    } else {
     
    109138     
    110139      if (WIFEXITED(waitstatus)) {
    111         gprint (GP_ERR, "child exited with status %d\n", WEXITSTATUS(waitstatus));
     140        if (VerboseMode()) gprint (GP_ERR, "child exited with status %d\n", WEXITSTATUS(waitstatus));
    112141      }
    113142      if (WIFSIGNALED(waitstatus)) {
    114         gprint (GP_ERR, "child crashed with status %d\n", WTERMSIG(waitstatus));
     143        if (VerboseMode()) gprint (GP_ERR, "child crashed with status %d\n", WTERMSIG(waitstatus));
    115144      }
    116145      if (WIFSTOPPED(waitstatus)) {
    117         gprint (GP_ERR, "waitpid returns 'stopped': programming error\n");
     146        if (VerboseMode()) gprint (GP_ERR, "waitpid returns 'stopped': programming error\n");
    118147        exit (1);
    119148      }
Note: See TracChangeset for help on using the changeset viewer.