Ignore:
Timestamp:
07/27/10 07:27:04 (14 years ago)
Author:
ogrimm
Message:
Removed mutex locking in hvcontrol, use lockf() in Communicate()
File:
1 edited

Legend:

Unmodified
Added
Removed
  • hvcontrol/src/ProcessIO.cc

    r230 r264  
    3030        {"rate", &ProcessIO::cmd_rate, 1, "<rate>", "Set status refresh rate in Hz"},
    3131        {"timeout", &ProcessIO::cmd_timeout, 1, "<time>", "Set timeout to return from read in seconds"},
    32         {"reset", &ProcessIO::cmd_reset, 0, "", "Reset active bias board"},
     32        {"reset", &ProcessIO::cmd_reset, 0, "", "Reset active bias boards"},
    3333        {"start", &ProcessIO::cmd_start, 0, "", "Start bias status monitor"},
    3434        {"stop", &ProcessIO::cmd_stop, 0, "", "Stop bias status monitor"},
     
    5353  FirstBoard  = 0;
    5454  LastBoard   = -1;
    55 
    56   // Initialize mutex for thread synchronisation
    57   if (pthread_mutex_init(&Mutex, NULL) != 0) {
    58     Message(FATAL, "pthread_mutex_init() failed");
    59   }
    6055
    6156  // DIM console service used in PrintMessage()
     
    109104  delete calib;
    110105  delete ConsoleOut;   
    111   free(ConsoleText);
    112  
    113   // Destroy mutex
    114   if (pthread_mutex_destroy(&Mutex) != 0) Message(ERROR, "pthread_mutex_destroy() failed");
     106  free(ConsoleText); 
    115107}
    116108
     
    370362void ProcessIO::cmd_reset() {
    371363
    372   for (int i=FirstBoard; i<=LastBoard; i++) ResetBoard(i);
     364  for (int i=FirstBoard; i<=LastBoard; i++) {
     365        if (fHVBoard[i]->Reset() == 1) {
     366          PrintMessage("Reset of board %d\n", fHVBoard[i]->GetBoardNumber());
     367          PrintBoardStatus(i);
     368        }
     369        else PrintMessage("Error: Could not reset board %d\n",fHVBoard[i]->GetBoardNumber());
     370  }
    373371}
    374372
     
    527525
    528526  static bool Warned = false;
    529   int Ret;
    530 
    531   // Lock because command execution runs in different thread
    532   if ((Ret = pthread_mutex_lock(&Mutex)) != 0) {
    533         Message(FATAL, "pthread_mutex_lock() failed in commandHandler() (%s)", strerror(Ret));
    534   }
    535527
    536528  for (int i=0; i<NumHVBoards; i++) {
     
    549541    if (fHVBoard[i]->ResetButton) {
    550542      Message(INFO, "Manual reset of board %d", fHVBoard[i]->GetBoardNumber());
    551       ResetBoard(i);
     543          fHVBoard[i]->Reset();
    552544    }
    553545   
     
    558550    for (int j=0; j<NUM_CHAINS; j++) {
    559551      if (fHVBoard[i]->Overcurrent[j]) {
    560                 Message(WARN, "Warning: Overcurrent in chain %d of board %d",j,fHVBoard[i]->GetBoardNumber());
    561                 ResetBoard(i);
     552                Message(WARN, "Warning: Overcurrent in chain %d of board %d, resetting board",j,fHVBoard[i]->GetBoardNumber());
     553                fHVBoard[i]->Reset();
    562554      }
    563555    }
    564   }
    565  
    566   // Unlock
    567   if ((Ret = pthread_mutex_unlock(&Mutex)) != 0) {
    568         Message(FATAL, "pthread_mutex_lock() failed in commandHandler() (%s)", strerror(Ret));
    569   }
    570 
    571 }
    572 
    573 
    574 // Send reset to board and clear voltage arrays
    575 void ProcessIO::ResetBoard(int i) {
    576    
    577   if (fHVBoard[i]->Reset() == 1) {
    578     PrintMessage("Reset of board %d\n", fHVBoard[i]->GetBoardNumber());
    579     PrintBoardStatus(i);
    580   }
    581   else PrintMessage("Error: Could not reset board %d\n",fHVBoard[i]->GetBoardNumber());
    582 }
     556  } 
     557}
     558
    583559
    584560
     
    597573
    598574
    599 // Command handling (mutex needed because of monitor thread)
     575// Command handling
    600576void ProcessIO::commandHandler() {
    601577
    602   int Ret;
    603 
    604   if ((Ret = pthread_mutex_lock(&Mutex)) != 0) {
    605         Message(FATAL, "pthread_mutex_lock() failed in commandHandler() (%s)", strerror(Ret));
    606   }
    607 
    608578  if ((getCommand()==Command) && (*(Command->getString()+Command->getSize()-1)=='\0')) {
    609         SendToLog("Command '%s' from %s (ID %d)", Command->getString(), getClientName(), getClientId());
    610579        CommandControl(Command->getString());
    611   }
    612 
    613   if ((Ret = pthread_mutex_unlock(&Mutex)) != 0) {
    614         Message(FATAL, "pthread_mutex_unlock() failed in commandHandler() (%s)", strerror(Ret));
    615580  }
    616581}
Note: See TracChangeset for help on using the changeset viewer.