pun intended) that I'm touching the time library.
Brian Schack reported that the traffic scheduler messes up the timestamps
of the atlas network output. As it turns out, the c library functions
asctime, and gmtime use a static copy of the tm struct to do the internal
formatting. Our linux port of the SGTime class, incidentally, also stored
it's master time stamp in this very same struct. Thus, formatting an
arbitrary time value, would have the unwanted side effect of time travel.
Usually, this would go unnoticed, because the actual time parameters would
be updated before any damage could be done. But unwanted side effects, as
in Brian's example could occur.
On the MSVC port this appears to not have been a problem. Since that port
used a copy of the tm struct to store it's master time stamps. Since the
MSVC code also compiles cleanly on linux, it seems to be the way to go to
use that approach. In addition, it also removes some conditional compile
directives.
I've only run a short test, but didn't see any undesirable side effects.
{
double gst_precise, gst_course;
{
double gst_precise, gst_course;
-#if defined(_MSC_VER) || defined(__MINGW32__)
SG_LOG( SG_EVENT, SG_DEBUG, "Updating time" );
SG_LOG( SG_EVENT, SG_DEBUG, "Updating time" );
<< " warp = " << warp );
// get GMT break down for current time
<< " warp = " << warp );
// get GMT break down for current time
-#if defined(_MSC_VER) || defined(__MINGW32__)
memcpy( gmt, gmtime(&cur_time), sizeof(tm) );
memcpy( gmt, gmtime(&cur_time), sizeof(tm) );
-#else
- gmt = gmtime(&cur_time);
-#endif
SG_LOG( SG_EVENT, SG_DEBUG,
" Current GMT = " << gmt->tm_mon+1 << "/"
<< gmt->tm_mday << "/" << (1900 + gmt->tm_year) << " "
SG_LOG( SG_EVENT, SG_DEBUG,
" Current GMT = " << gmt->tm_mon+1 << "/"
<< gmt->tm_mday << "/" << (1900 + gmt->tm_year) << " "
// since 1900 jan 0.5), mjd.
double sgTimeCurrentMJD( time_t ct, long int warp ) {
// since 1900 jan 0.5), mjd.
double sgTimeCurrentMJD( time_t ct, long int warp ) {
-#if defined(_MSC_VER) || defined(__MINGW32__)
struct tm m_gmt; // copy of system gmtime(&time_t) structure
struct tm *gmt = &m_gmt;
struct tm m_gmt; // copy of system gmtime(&time_t) structure
struct tm *gmt = &m_gmt;
-#else
- struct tm *gmt;
-#endif
// get current Unix calendar time (in seconds)
// warp += warp_delta;
// get current Unix calendar time (in seconds)
// warp += warp_delta;
<< " warp = " << warp );
// get GMT break down for current time
<< " warp = " << warp );
// get GMT break down for current time
-#if defined(_MSC_VER) || defined(__MINGW32__)
memcpy( gmt, gmtime(&cur_time), sizeof(tm) );
memcpy( gmt, gmtime(&cur_time), sizeof(tm) );
-#else
- gmt = gmtime(&cur_time);
-#endif
SG_LOG( SG_EVENT, SG_DEBUG,
" Current GMT = " << gmt->tm_mon+1 << "/"
<< gmt->tm_mday << "/" << (1900 + gmt->tm_year) << " "
SG_LOG( SG_EVENT, SG_DEBUG,
" Current GMT = " << gmt->tm_mon+1 << "/"
<< gmt->tm_mday << "/" << (1900 + gmt->tm_year) << " "
time_t cur_time;
// Break down of equivalent GMT time
time_t cur_time;
// Break down of equivalent GMT time
-#if defined(_MSC_VER) || defined(__MINGW32__)
struct tm m_gmt; // copy of system gmtime(&time_t) structure
struct tm m_gmt; // copy of system gmtime(&time_t) structure
-#else
- struct tm *gmt;
-#endif
// offset of local time relative to GMT
time_t local_offset;
// offset of local time relative to GMT
time_t local_offset;
inline const char * get_zonename() const { return zonename.c_str(); }
/** @return GMT in a "brokent down" tm structure */
inline const char * get_zonename() const { return zonename.c_str(); }
/** @return GMT in a "brokent down" tm structure */
-#if defined(_MSC_VER) || defined(__MINGW32__)
inline struct tm* getGmt()const { return (struct tm *)&m_gmt; };
inline struct tm* getGmt()const { return (struct tm *)&m_gmt; };
-#else
- inline struct tm* getGmt()const { return gmt; };
-#endif
/** @return julian date */
inline double getJD() const { return jd; };
/** @return julian date */
inline double getJD() const { return jd; };