IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 25, 2009, 11:56:09 AM (17 years ago)
Author:
eugene
Message:

upgrade threading/locking model for pantasks: changes merged from eam_branch_20090322

File:
1 edited

Legend:

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

    r20032 r23530  
    1212
    1313/* local static variables to track the controller host properties */
     14/* these are used by AddHost and DeleteHost, and are only called by controller_host.c (clientThread) */
     15/* or by RestartController : lock between these two? */
    1416static Host *hosts = NULL;
    1517static int Nhosts = 0;
     
    3133}
    3234
     35// XXX possible race condition problem: if we delete a host while the controller
     36// is being restarted.  to fix this, we need to keep the deletion in controller_thread,
     37// but perhaps mark it in the client_thread?
    3338int DeleteHost (char *hostname) {
    3439
     
    261266  }
    262267
     268  // This function is called by the JobTaskThread via SubmitJob.  We need to unlock the
     269  // JobTaskLock to avoid a dead lock with the JobTaskLock called in CheckController
     270  JobTaskUnlock();
     271  ControlLock(__func__);
    263272  InitIOBuffer (&buffer, 0x100);
    264273  status = ControllerCommand (cmd, CONTROLLER_PROMPT, &buffer);
    265274  free (cmd);
     275  ControlUnlock(__func__);
     276  JobTaskLock();
     277
    266278
    267279  /* extract the job PID from the controller response */
     
    411423  if ((status == -1) && (errno == EPIPE)) {
    412424    StopController ();
    413     gprint (GP_ERR, "controller is down (pipe closed), restarting\n");
     425    fprintf (stderr, "controller is down (pipe closed), restarting\n");
    414426    if (!RestartController ()) {
    415427      return (FALSE);
     
    434446    if (status ==  0) {
    435447      StopController ();
    436       gprint (GP_ERR, "controller is down (EOF), restarting\n");
     448      fprintf (stderr, "controller is down (EOF), restarting\n");
    437449      if (!RestartController ()) {
    438450        return (FALSE);
     
    441453    }
    442454    if (status == -1) {
    443       gprint (GP_ERR, "controller is not responding (%d tries)\n", j);
     455      fprintf (stderr, "controller is not responding (%d tries)\n", j);
    444456      gwrite (buffer[0].buffer, 1, buffer[0].Nbuffer, GP_ERR);
    445457    }
    446458  }
    447459  if (status == -1) {
    448     gprint (GP_ERR, "controller still not responding, giving up\n");
     460    fprintf (stderr, "controller still not responding, giving up\n");
    449461    return (FALSE);
    450462  }
     
    456468    bzero (buffer[0].buffer + buffer[0].Nbuffer, buffer[0].Nalloc - buffer[0].Nbuffer);
    457469  }
    458   /* if (VerboseMode()) gprint (GP_ERR, "message received, %d cycles\n", i); */
     470  if (VerboseMode()) fprintf (stderr, "message received, %d cycles\n", i);
    459471  return (TRUE);
    460472}
     
    492504}
    493505
     506void PrintControllerBusyJobs () {
     507
     508  int status;
     509  char command[1024];
     510  IOBuffer buffer;
     511
     512  /* check if controller is running */
     513  status = CheckControllerStatus ();
     514  if (!status) {
     515    return;
     516  }
     517
     518  sprintf (command, "jobstack busy");
     519  InitIOBuffer (&buffer, 0x100);
     520
     521  status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer);
     522
     523  if (status) {
     524    gprint (GP_LOG, " jobs currently running remotely:\n");
     525    gwrite (buffer.buffer, 1, buffer.Nbuffer, GP_LOG);
     526  } else {
     527    gprint (GP_LOG, "controller is not responding\n");
     528  }
     529  FreeIOBuffer (&buffer);
     530  return;
     531}
     532
    494533int PrintControllerOutput () {
    495534
     
    581620  InitIOBuffer (&buffer, 0x100);
    582621
    583   // XXX lock the host table? SerialThreadLock ();
     622  // XXX lock the host table? no: that would risk a dead lock between client and controller threads:
    584623  gprint (GP_ERR, "pcontrol restarted, reloading hosts\n");
    585624  for (i = 0; i < Nhosts; i++) {
     
    588627    status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer);
    589628  }
    590   // SerialThreadUnlock ();
    591629
    592630  if (status) gwrite (buffer.buffer, 1, buffer.Nbuffer, GP_LOG);
Note: See TracChangeset for help on using the changeset viewer.