Changeset 182 for drsdaq/drsdaq.cpp
- Timestamp:
- 03/12/10 15:53:20 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
drsdaq/drsdaq.cpp
r110 r182 30 30 void SignalHandler(int); 31 31 void CrashHandler(int); 32 void ExitFunction(); 32 33 33 34 // ================ … … 84 85 signal(SIGINT, &CrashHandler); 85 86 signal(SIGHUP, &CrashHandler); 86 87 atexit(&ExitFunction); 88 87 89 // Construct main instance and create mutex for thread synchronization 88 DAQReadout dreadout (argc==3 ? argv[2] : DEFAULT_CONFIG);90 DAQReadout dreadout; 89 91 if (pthread_mutex_init(&dreadout.control_mutex, NULL) != 0) { 90 92 perror("pthread_mutex_init failed"); … … 92 94 } 93 95 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); 115 114 116 115 // Destruct mutex and main instance … … 282 281 return; 283 282 } 283 284 // This function will be implicitly called by exit() 285 void ExitFunction() { 286 remove(LOCKFILE); 287 return; 288 }
Note:
See TracChangeset
for help on using the changeset viewer.