const std::string *progName;
/** A pointer to the CommandExecutor (the signal handlers need it) */
- CVC4::main::CommandExecutor* pExecutor = nullptr;
+ std::unique_ptr<CVC4::main::CommandExecutor> pExecutor;
+
+ /** The time point the binary started, accessible to signal handlers */
+ std::unique_ptr<TotalTimer> totalTime;
+
+ TotalTimer::~TotalTimer()
+ {
+ if (pExecutor != nullptr)
+ {
+ auto duration = std::chrono::steady_clock::now() - d_start;
+ pExecutor->getSmtEngine()->setTotalTimeStatistic(
+ std::chrono::duration<double>(duration).count());
+ }
+ }
}/* CVC4::main namespace */
}/* CVC4 namespace */
}
int runCvc4(int argc, char* argv[], Options& opts) {
-
- std::chrono::time_point totalTimeStart = std::chrono::steady_clock::now();
+ main::totalTime = std::make_unique<TotalTimer>();
// For the signal handlers' benefit
pOptions = &opts;
(*(opts.getOut())) << language::SetLanguage(opts.getOutputLanguage());
// Create the command executor to execute the parsed commands
- pExecutor = new CommandExecutor(opts);
+ pExecutor = std::make_unique<CommandExecutor>(opts);
int returnValue = 0;
{
// or other on_exit/atexit stuff.
_exit(returnValue);
#endif /* CVC4_COMPETITION_MODE */
- pExecutor->getSmtEngine()->setResultStatistic(result.toString());
- std::chrono::duration totalTime = std::chrono::steady_clock::now() - totalTimeStart;
- pExecutor->getSmtEngine()->setTotalTimeStatistic(std::chrono::duration<double>(totalTime).count());
+ totalTime.reset();
pExecutor->flushOutputStreams();
#ifdef CVC4_DEBUG
#endif /* CVC4_DEBUG */
}
- delete pExecutor;
-
- pExecutor = nullptr;
+ pExecutor.reset();
signal_handlers::cleanup();
** Header for main CVC4 driver.
**/
+#include <chrono>
#include <exception>
+#include <memory>
#include <string>
#include "base/exception.h"
extern const std::string* progName;
/** A reference for use by the signal handlers to print statistics */
-extern CVC4::main::CommandExecutor* pExecutor;
+extern std::unique_ptr<CVC4::main::CommandExecutor> pExecutor;
+
+/** Manages a custom timer for the total runtime in RAII-style. */
+class TotalTimer
+{
+ public:
+ TotalTimer() : d_start(std::chrono::steady_clock::now()) {}
+ ~TotalTimer();
+
+ private:
+ std::chrono::steady_clock::time_point d_start;
+};
+/** The time point the binary started, accessible to signal handlers */
+extern std::unique_ptr<TotalTimer> totalTime;
/**
* If true, will not spin on segfault even when CVC4_DEBUG is on.