FACT++  1.0
void runLogWatchDog ( )

Definition at line 2125 of file feeserver.c.

References checkReplicatedLogMessage(), createLogMessage(), and dtq_sleep().

Referenced by startLogWatchDogThread().

2125  {
2126  int status = -1;
2127  unsigned int sleepSec = 0;
2128  unsigned int sleepMilliSec = 0;
2129 
2130  // set cancelation type
2131  status = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
2132  if (status != 0) {
2133 # ifdef __DEBUG
2134  printf("Set cancel state error [LogWatchDog]: %d\n", status);
2135  fflush(stdout);
2136 # endif
2137  createLogMessage(MSG_WARNING,
2138  "Can not set cancel state for LogWatchDog thread. WatchDog should not not be affected.",
2139  0);
2140  }
2141  status = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
2142  if (status != 0) {
2143 # ifdef __DEBUG
2144  printf("Set cancel type error [LogWatchDog]: %d\n", status);
2145  fflush(stdout);
2146 # endif
2147  createLogMessage(MSG_WARNING,
2148  "Can not set cancel type for LogWatchDog thread. WatchDog should not not be affected.",
2149  0);
2150  }
2151 
2152  // thread started successfully, set flag accordingly
2153  logWatchDogRunning = true;
2154  createLogMessage(MSG_DEBUG,
2155  "LogWatchDog thread for filtering replicated log messages successfully started.",
2156  0);
2157 # ifdef __DEBUG
2158  printf("LogWatchDog thread for filtering replicated log messages successfully started.\n");
2159  fflush(stdout);
2160 # endif
2161 
2162  while (1) {
2163  // before test for replicated messages lock mutex,
2164  // DON'T call createLogMessage() inside mutex lock
2165  status = pthread_mutex_lock(&log_mut);
2166  // discard eventual error, this would cause more problems
2167 # ifdef __DEBUG
2168  if (status != 0) {
2169  printf("Lock log mutex error: %d\n", status);
2170  fflush(stdout);
2171  }
2172 # endif
2173 
2174  // perform check here
2176 
2177  // release mutex
2178  status = pthread_mutex_unlock(&log_mut);
2179  // discard eventual error, this would cause more problems
2180 # ifdef __DEBUG
2181  if (status != 0) {
2182  printf("Unlock log mutex error: %d\n", status);
2183  fflush(stdout);
2184  }
2185 # endif
2186 
2187  // set cancelation point
2188  pthread_testcancel();
2189  // prepare sleep time (timeout)
2190  sleepSec = logWatchDogTimeout / 1000;
2191  sleepMilliSec = logWatchDogTimeout % 1000;
2192  usleep(sleepMilliSec * 1000);
2193  dtq_sleep(sleepSec);
2194  // set cancelation point
2195  pthread_testcancel();
2196  }
2197 
2198  // should never be reached !
2199  pthread_exit(0);
2200 }
unsigned int dtq_sleep(int secs)
Definition: dtq.c:837
void createLogMessage(unsigned int type, char *description, char *origin)
Definition: feeserver.c:1530
bool checkReplicatedLogMessage()
Definition: feeserver.c:2202
static unsigned int logWatchDogTimeout
Definition: feeserver.c:133
static pthread_mutex_t log_mut
Definition: feeserver.c:272
static bool logWatchDogRunning
Definition: feeserver.c:122

+ Here is the call graph for this function:

+ Here is the caller graph for this function: