message: pcm-tsx: support -i parameter
  address
diff: @@ -166,6 +166,7 @@ void print_usage(const string progname)
  cerr << " -F | -force => force running this program despite lack of HW RTM support (optional)\n";
  cerr << " -csv[=file.csv] | /csv[=file.csv] => output compact CSV format to screen or\n"
  << " to a file, in case filename is provided\n";
  + cerr << " -i[=number] | /i[=number] => allow to determine number of iterations\n";
  cerr << " [-e event1] [-e event2] [-e event3]=> optional list of custom TSX events to monitor (up to 4)."
  << " The list of supported events:\n";
  for (auto & e: eventDefinition)
  @@ -285,6 +286,7 @@ int main(int argc, char * argv[])
  long diff_usec = 0; // deviation of clock is useconds between measurements
  bool force = false;
  int calibrated = PCM_CALIBRATION_INTERVAL - 2; // keeps track is the clock calibration needed
  + MainLoop mainLoop;
  string program = string(argv[0]);
  PCM * m = PCM::getInstance();
  @@ -326,6 +328,10 @@ int main(int argc, char * argv[])
  }
  continue;
  }
  + else if (mainLoop.parseArg(*argv))
  + {
  + continue;
  + }
  else if (strncmp(*argv, "-e", 2) == 0)
  {
  argv++;
  @@ -498,7 +504,7 @@ int main(int argc, char * argv[])
  MySystem(sysCmd, sysArgv);
  }
  - while (1)
  + mainLoop([&]()
  {
  if (!csv) cout << std::flush;
  int delay_ms = int(delay * 1000);
  @@ -518,7 +524,7 @@ int main(int argc, char * argv[])
  }
  #endif
  - if (sysCmd == NULL || m->isBlocked() == false)
  + if (sysCmd == NULL || mainLoop.getNumberOfIterations() != 0 || m->isBlocked() == false)
  {
  MySleepMs(calibrated_delay_ms);
  }
  @@ -612,8 +618,9 @@ int main(int argc, char * argv[])
  if (m->isBlocked()) {
  // in case PCM was blocked after spawning child application: break monitoring loop here
  - break;
  - }
  + return false;
  }
  + return true;
  + });
  exit(EXIT_SUCCESS);
  }
  