From 5e8b536bc2903f787b5f6c5e09a5b2373015d9cf Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Sat, 25 Feb 2006 07:02:21 +0000 Subject: [PATCH] timers --- Common/Timer.cpp | 20 +++++++++++--------- Common/Timer.h | 4 ++-- Fltk/Callbacks.cpp | 10 +++++----- Parser/Gmsh.tab.cpp | 4 ++-- Parser/Gmsh.y | 4 ++-- Parser/Gmsh.yy.cpp | 4 ++-- TODO | 7 +------ 7 files changed, 25 insertions(+), 28 deletions(-) diff --git a/Common/Timer.cpp b/Common/Timer.cpp index 991d559783..24b4a9c81b 100644 --- a/Common/Timer.cpp +++ b/Common/Timer.cpp @@ -1,4 +1,4 @@ -// $Id: Timer.cpp,v 1.18 2006-02-25 00:15:00 geuzaine Exp $ +// $Id: Timer.cpp,v 1.19 2006-02-25 07:02:20 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -25,16 +25,17 @@ #include <sys/time.h> #include <unistd.h> -long GetTimeMilliSeconds() +double GetTimeInSeconds() { struct timeval tp; gettimeofday(&tp, (struct timezone *)0); - return (long)tp.tv_sec * 1000000 + (long)tp.tv_usec; + double t = (double)tp.tv_sec + 1.e-6 * (double)tp.tv_usec; + return t; } -void SleepMilliSeconds(int ms) +void SleepInSeconds(double s) { - usleep(1000 * ms); + usleep((long)(1.e6 * s)); } #else // pure windows @@ -42,16 +43,17 @@ void SleepMilliSeconds(int ms) #include "Gmsh.h" #include <windows.h> -long GetTimeMilliSeconds() +long GetTimeInSeconds() { FILETIME ft; GetSystemTimeAsFileTime(&ft); - return (long)ft.dwHighDateTime * 100000 + (long)ft.dwLowDateTime / 10; + double t = 1.e2 * (double)ft.dwHighDateTime; + return t; } -void SleepMilliSeconds(int ms) +void SleepInSeconds(double s) { - Sleep(ms); + Sleep((long)(1.e3 * s)); } #endif diff --git a/Common/Timer.h b/Common/Timer.h index 4d380bbc3d..51a227829e 100644 --- a/Common/Timer.h +++ b/Common/Timer.h @@ -20,7 +20,7 @@ // // Please report all bugs and problems to <gmsh@geuz.org>. -long GetTimeMilliSeconds(); -void SleepMilliSeconds(int ms); +double GetTimeInSeconds(); +void SleepInSeconds(double s); #endif diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp index 733f20ae54..d2b50e3d92 100644 --- a/Fltk/Callbacks.cpp +++ b/Fltk/Callbacks.cpp @@ -1,4 +1,4 @@ -// $Id: Callbacks.cpp,v 1.410 2006-02-25 00:15:00 geuzaine Exp $ +// $Id: Callbacks.cpp,v 1.411 2006-02-25 07:02:20 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -520,15 +520,15 @@ void ManualPlay(int time, int step) void status_play_cb(CALLBACK_ARGS) { - static long anim_time; + static double anim_time; WID->set_anim_buttons(0); stop_anim = 0; - anim_time = GetTimeMilliSeconds(); + anim_time = GetTimeInSeconds(); while(1) { if(stop_anim) break; - if(GetTimeMilliSeconds() - anim_time > 1.e6 * CTX.post.anim_delay) { - anim_time = GetTimeMilliSeconds(); + if(GetTimeInSeconds() - anim_time > CTX.post.anim_delay) { + anim_time = GetTimeInSeconds(); ManualPlay(!CTX.post.anim_cycle, 1); } WID->check(); diff --git a/Parser/Gmsh.tab.cpp b/Parser/Gmsh.tab.cpp index e90b551b4d..0d97676716 100644 --- a/Parser/Gmsh.tab.cpp +++ b/Parser/Gmsh.tab.cpp @@ -125,7 +125,7 @@ #line 1 "Gmsh.y" -// $Id: Gmsh.tab.cpp,v 1.258 2006-02-24 22:08:13 geuzaine Exp $ +// $Id: Gmsh.tab.cpp,v 1.259 2006-02-25 07:02:20 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -4479,7 +4479,7 @@ case 129: #line 1832 "Gmsh.y" { if(!strcmp(yyvsp[-2].c, "Sleep")){ - SleepMilliSeconds((int)(yyvsp[-1].d * 1000.)); + SleepInSeconds(yyvsp[-1].d); } else if(!strcmp(yyvsp[-2].c, "Remesh")){ ReMesh(THEM); diff --git a/Parser/Gmsh.y b/Parser/Gmsh.y index be879dcff6..3b0dcbf8ab 100644 --- a/Parser/Gmsh.y +++ b/Parser/Gmsh.y @@ -1,5 +1,5 @@ %{ -// $Id: Gmsh.y,v 1.221 2006-02-24 22:07:08 geuzaine Exp $ +// $Id: Gmsh.y,v 1.222 2006-02-25 07:02:21 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -1831,7 +1831,7 @@ Command : | tSTRING FExpr tEND { if(!strcmp($1, "Sleep")){ - SleepMilliSeconds((int)($2 * 1000.)); + SleepInSeconds($2); } else if(!strcmp($1, "Remesh")){ ReMesh(THEM); diff --git a/Parser/Gmsh.yy.cpp b/Parser/Gmsh.yy.cpp index d8e230010f..51efcd24e8 100644 --- a/Parser/Gmsh.yy.cpp +++ b/Parser/Gmsh.yy.cpp @@ -2,7 +2,7 @@ /* A lexical scanner generated by flex */ /* Scanner skeleton version: - * $Header: /cvsroot/gmsh/Parser/Gmsh.yy.cpp,v 1.257 2006-02-24 22:08:13 geuzaine Exp $ + * $Header: /cvsroot/gmsh/Parser/Gmsh.yy.cpp,v 1.258 2006-02-25 07:02:21 geuzaine Exp $ */ #define FLEX_SCANNER @@ -727,7 +727,7 @@ char *yytext; #line 1 "Gmsh.l" #define INITIAL 0 #line 2 "Gmsh.l" -// $Id: Gmsh.yy.cpp,v 1.257 2006-02-24 22:08:13 geuzaine Exp $ +// $Id: Gmsh.yy.cpp,v 1.258 2006-02-25 07:02:21 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // diff --git a/TODO b/TODO index b0b6e1860f..e845af13bf 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -$Id: TODO,v 1.122 2006-02-22 17:25:03 geuzaine Exp $ +$Id: TODO,v 1.123 2006-02-25 07:02:20 geuzaine Exp $ ******************************************************************** @@ -38,12 +38,7 @@ curve/surface/volume or loop over all elements.) ******************************************************************** On Windows WITHOUT Cygwin: -- rewrite solver interface (GmshServer and GmshClient) - Functions in parser don't seem to work -- fix compilation issues in triangle (timezone) and gl2ps (zlib??) -- need alternative timer functions (Timer.cpp, ParUtils.cpp) -- there is a bug in fwrite/fread as used for binary post-processing - views (need to investigate "premature end of file" message) ******************************************************************** -- GitLab