diff options
author | knarf <knarf@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2012-10-24 15:17:58 +0000 |
---|---|---|
committer | knarf <knarf@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2012-10-24 15:17:58 +0000 |
commit | 7b408d1cc5125e2a9ef4da8194cbd752312ffe13 (patch) | |
tree | edbfbbc76136f7bbce05399d1ccaffbd22e594c5 | |
parent | cfd4ef58bdb2337e1791ecbc007b13cb90576792 (diff) |
Add a flag indicating if a timer is running or not.
Starting a running timer and stopping a not running timer will produce a level 1 warning and will otherwise do nothing (will not actually start/stop twice). This fixes the issue at hand - although it will now produce that warning for the total simulation time timer - which is stopped multiple times within Carpet.
git-svn-id: http://svn.cactuscode.org/flesh/trunk@4889 17b73243-c579-4c4c-a9d2-2d5706c11dac
-rw-r--r-- | src/util/CactusTimers.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/util/CactusTimers.c b/src/util/CactusTimers.c index cc4e75cb..1f6b718a 100644 --- a/src/util/CactusTimers.c +++ b/src/util/CactusTimers.c @@ -62,6 +62,7 @@ void CCTK_FCALL CCTK_FNAME (CCTK_TimerPrintData) typedef struct { void **data; + int running; /* 1 or 0 depending on timer running or not */ } t_Timer; @@ -421,6 +422,7 @@ static int CCTKi_TimerCreate (const char *timername) if (timer) { + timer->running = 0; timer->data = (void **) malloc (n_clocks * sizeof (void *)); if (timer->data) @@ -667,6 +669,13 @@ int CCTK_TimerStartI (int this_timer) timer = Util_GetHandledData (timers, this_timer); if (timer) { + if (timer->running) + { + CCTK_VWarn(1, __LINE__, __FILE__, "Cactus", + "CCTK_TimerStartI: Trying to start timer \"%s\" (%d) which " + "is already running.", Util_GetHandleName(timers, this_timer), + this_timer); + } CCTKi_TimerStart (this_timer, timer); } else @@ -709,6 +718,12 @@ static void CCTKi_TimerStart (int this_timer, t_Timer *timer) const cClockFuncs *funcs; int handle; + /* If timer is running already, ignore call. Errors have to be reported + * by calling functions if wanted. */ + if (timer && timer->running) + { + return; + } if (timer && timer->data) { @@ -718,6 +733,7 @@ static void CCTKi_TimerStart (int this_timer, t_Timer *timer) funcs = (const cClockFuncs *) Util_GetHandledData (clocks, handle); funcs->start (this_timer, timer->data[handle]); } + timer->running = 1; } } @@ -799,6 +815,13 @@ int CCTK_TimerStopI (int this_timer) timer = Util_GetHandledData (timers, this_timer); if (timer) { + if (!timer->running) + { + CCTK_VWarn(1, __LINE__, __FILE__, "Cactus", + "CCTK_TimerStopI: Trying to stop timer \"%s\" (%d) which " + "isn't running.", Util_GetHandleName(timers, this_timer), + this_timer); + } CCTKi_TimerStop (this_timer, timer); } else @@ -841,6 +864,13 @@ static void CCTKi_TimerStop (int this_timer, t_Timer *timer) const cClockFuncs *funcs; int handle; + /* Do nothing if timer isn't running. Warning messages have to be produced + * in CCTK_TimerStopI, so this shouldn't be reached in theory */ + if (timer && !timer->running) + { + return; + } + if (timer && timer->data) { /* Stop the timer info for this timer */ @@ -849,6 +879,7 @@ static void CCTKi_TimerStop (int this_timer, t_Timer *timer) funcs = (const cClockFuncs *) Util_GetHandledData (clocks, handle); funcs->stop (this_timer, timer->data[handle]); } + timer->running = 0; } } |