diff --git a/src/libCom/os/WIN32/osdTime.cc b/src/libCom/os/WIN32/osdTime.cc index 00252043d..a7b2d32a0 100644 --- a/src/libCom/os/WIN32/osdTime.cc +++ b/src/libCom/os/WIN32/osdTime.cc @@ -18,6 +18,7 @@ static unsigned long offset_secs; static DWORD prev_time = 0; static UINT res; +static char init = 0; /* * init_osi_time has to be called before using the timer, @@ -27,6 +28,10 @@ int init_osi_time () { TIMECAPS tc; + if (init) { + return 1; + } + if (timeGetDevCaps (&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) { fprintf (stderr, "init_osi_time: cannot get timer info\n"); @@ -42,13 +47,19 @@ int init_osi_time () prev_time = timeGetTime(); offset_secs = (long)time(NULL) - (long)prev_time/1000; + init = 1; return 0; } int exit_osi_time () { + if (!init) { + return 0; + } + timeEndPeriod (res); + init = 0; return 0; } @@ -59,7 +70,16 @@ int exit_osi_time () // osiTime osiTime::getCurrent () { - unsigned long now; + unsigned long now; + + /* + * this allows the code to work when it is in an object + * library (in addition to inside a dll) + */ + if (!init) { + init_osi_time(); + init = 1; + } /* MS Online help: * Note that the value returned by the timeGetTime function is diff --git a/src/libCom/osi/os/WIN32/osdTime.cpp b/src/libCom/osi/os/WIN32/osdTime.cpp index 00252043d..a7b2d32a0 100644 --- a/src/libCom/osi/os/WIN32/osdTime.cpp +++ b/src/libCom/osi/os/WIN32/osdTime.cpp @@ -18,6 +18,7 @@ static unsigned long offset_secs; static DWORD prev_time = 0; static UINT res; +static char init = 0; /* * init_osi_time has to be called before using the timer, @@ -27,6 +28,10 @@ int init_osi_time () { TIMECAPS tc; + if (init) { + return 1; + } + if (timeGetDevCaps (&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) { fprintf (stderr, "init_osi_time: cannot get timer info\n"); @@ -42,13 +47,19 @@ int init_osi_time () prev_time = timeGetTime(); offset_secs = (long)time(NULL) - (long)prev_time/1000; + init = 1; return 0; } int exit_osi_time () { + if (!init) { + return 0; + } + timeEndPeriod (res); + init = 0; return 0; } @@ -59,7 +70,16 @@ int exit_osi_time () // osiTime osiTime::getCurrent () { - unsigned long now; + unsigned long now; + + /* + * this allows the code to work when it is in an object + * library (in addition to inside a dll) + */ + if (!init) { + init_osi_time(); + init = 1; + } /* MS Online help: * Note that the value returned by the timeGetTime function is