Changeset 182 for drsdaq/drsdaq.cpp


Ignore:
Timestamp:
03/12/10 15:53:20 (15 years ago)
Author:
ogrimm
Message:
Updates to DIM integration
File:
1 edited

Legend:

Unmodified
Added
Removed
  • drsdaq/drsdaq.cpp

    r110 r182  
    3030void SignalHandler(int);
    3131void CrashHandler(int);
     32void ExitFunction();
    3233
    3334// ================
     
    8485  signal(SIGINT, &CrashHandler);
    8586  signal(SIGHUP, &CrashHandler);
    86    
     87  atexit(&ExitFunction);
     88
    8789  // Construct main instance and create mutex for thread synchronization
    88   DAQReadout dreadout(argc==3 ? argv[2] : DEFAULT_CONFIG);
     90  DAQReadout dreadout;
    8991  if (pthread_mutex_init(&dreadout.control_mutex, NULL) != 0) {
    9092    perror("pthread_mutex_init failed");
     
    9294  }
    9395
    94   if (dreadout.ConfigOK) { // Normal program execution only if configuration was complete
    95     // Create threads
    96     if (pthread_mutex_init(&dreadout.control_mutex, NULL) != 0) {
    97       perror("pthread_mutex_init failed");
    98       throw;
    99     }
    100     if ((pthread_create(&thread_ConsoleCommand, NULL, (void * (*)(void *)) ConsoleCommand,(void *) &dreadout)) != 0) {
    101       perror("pthread_create failed with console thread");
    102       throw;
    103     }
    104     if ((pthread_create(&thread_CCCommand, NULL, (void * (*)(void *)) CCCommand,(void *) &dreadout)) != 0) {
    105       perror("pthread_create failed with socket thread");
    106       dreadout.SocketThread = NULL;
    107     }
    108     else dreadout.SocketThread = &thread_CCCommand;  // Thread should be accessible for sending signals 
    109 
    110     // Wait for threads to quit
    111     pthread_join(thread_ConsoleCommand, NULL);
    112     if(dreadout.SocketThread != NULL) pthread_join(thread_CCCommand, NULL);
    113   }
    114   else printf("Error: Configuration parameter missing in %s, terminating.\n", argc==3 ? argv[2] : DEFAULT_CONFIG);
     96  // Create threads
     97  if (pthread_mutex_init(&dreadout.control_mutex, NULL) != 0) {
     98    perror("pthread_mutex_init failed");
     99    throw;
     100  }
     101  if ((pthread_create(&thread_ConsoleCommand, NULL, (void * (*)(void *)) ConsoleCommand,(void *) &dreadout)) != 0) {
     102    perror("pthread_create failed with console thread");
     103    throw;
     104  }
     105  if ((pthread_create(&thread_CCCommand, NULL, (void * (*)(void *)) CCCommand,(void *) &dreadout)) != 0) {
     106    perror("pthread_create failed with socket thread");
     107    dreadout.SocketThread = NULL;
     108  }
     109  else dreadout.SocketThread = &thread_CCCommand;  // Thread should be accessible for sending signals 
     110
     111  // Wait for threads to quit
     112  pthread_join(thread_ConsoleCommand, NULL);
     113  if(dreadout.SocketThread != NULL) pthread_join(thread_CCCommand, NULL);
    115114 
    116115  // Destruct mutex and main instance
     
    282281  return;
    283282}
     283
     284// This function will be implicitly called by exit()
     285void ExitFunction() {
     286  remove(LOCKFILE);
     287  return;         
     288}
Note: See TracChangeset for help on using the changeset viewer.