Skip to content
Snippets Groups Projects
Commit 214e67d5 authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Fix in stopwatch

There was an assert checking that a stopwatch is not
started more then once. I replaced it with a counter
that, if a stopwatch is started N times, ignores the first
N-1 pause signals. This makes it possible to used Plumed.cmd
recursively. In practical terms, this makes it possible to use
DEBUG logRequestedAtoms
that was previosuly crashing the code.
parent f12fd73f
No related branches found
No related tags found
No related merge requests found
...@@ -106,11 +106,10 @@ const Stopwatch::Time & Stopwatch::Time::operator+=(const Time&t2){ ...@@ -106,11 +106,10 @@ const Stopwatch::Time & Stopwatch::Time::operator+=(const Time&t2){
} }
Stopwatch::Watch::Watch(): Stopwatch::Watch::Watch():
cycles(0),running(false),paused(false) { } cycles(0),running(0) { }
void Stopwatch::Watch::start(){ void Stopwatch::Watch::start(){
plumed_assert(!running); running++;
running=true;
lastStart=Time::get(); lastStart=Time::get();
} }
...@@ -124,9 +123,10 @@ void Stopwatch::Watch::stop(){ ...@@ -124,9 +123,10 @@ void Stopwatch::Watch::stop(){
} }
void Stopwatch::Watch::pause(){ void Stopwatch::Watch::pause(){
plumed_assert(running>0);
running--;
if(running!=0) return;
lap+=Time::get()-lastStart; lap+=Time::get()-lastStart;
plumed_assert(running);
running=false;
} }
void Stopwatch::start(const std::string & name){ void Stopwatch::start(const std::string & name){
......
...@@ -121,8 +121,7 @@ class Stopwatch{ ...@@ -121,8 +121,7 @@ class Stopwatch{
Time max; Time max;
Time min; Time min;
unsigned cycles; unsigned cycles;
bool running; unsigned running;
bool paused;
void start(); void start();
void stop(); void stop();
void pause(); void pause();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment