avoided to use a 64bit integer in vm_gettime() on os2 because some old compilers don't have the 64 bit type

This commit is contained in:
hyunghwan.chung 2018-12-01 14:52:24 +00:00
parent b5ae2ddea3
commit f625047af2

View File

@ -295,7 +295,7 @@ struct xtn_t
DWORD tc_overflow; DWORD tc_overflow;
#elif defined(__OS2__) #elif defined(__OS2__)
ULONG tc_last; ULONG tc_last;
ULONG tc_overflow; moo_ntime_t tc_last_ret;
#elif defined(__DOS__) #elif defined(__DOS__)
clock_t tc_last; clock_t tc_last;
moo_ntime_t tc_last_ret; moo_ntime_t tc_last_ret;
@ -874,18 +874,35 @@ static void log_write (moo_t* moo, moo_bitmask_t mask, const moo_ooch_t* msg, mo
{ {
tslen = sprintf(ts, "%04d-%02d-%02d %02d:%02d:%02d ", tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); tslen = sprintf(ts, "%04d-%02d-%02d %02d:%02d:%02d ", tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
} }
#elif defined(__OS2__)
#if defined(__WATCOMC__)
tmp = _localtime(&now, &tm);
#else
tmp = localtime(&now);
#endif
#if defined(__BORLANDC__)
/* the borland compiler doesn't handle %z properly - it showed 00 all the time */
tslen = strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S %Z ", tmp);
#else
tslen = strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S %z ", tmp);
#endif
if (tslen == 0)
{
tslen = sprintf(ts, "%04d-%02d-%02d %02d:%02d:%02d ", tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
}
#elif defined(__DOS__) #elif defined(__DOS__)
tmp = localtime(&now); tmp = localtime(&now);
/* since i know that %z/%Z is not available in strftime, i switch to sprintf immediately */ /* since i know that %z/%Z is not available in strftime, i switch to sprintf immediately */
tslen = sprintf(ts, "%04d-%02d-%02d %02d:%02d:%02d ", tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); tslen = sprintf(ts, "%04d-%02d-%02d %02d:%02d:%02d ", tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
#else #else
#if defined(__OS2__) #if defined(HAVE_LOCALTIME_R)
tmp = _localtime(&now, &tm);
#elif defined(HAVE_LOCALTIME_R)
tmp = localtime_r(&now, &tm); tmp = localtime_r(&now, &tm);
#else #else
tmp = localtime(&now); tmp = localtime(&now);
#endif #endif
#if defined(HAVE_STRFTIME_SMALL_Z) #if defined(HAVE_STRFTIME_SMALL_Z)
tslen = strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S %z ", tmp); tslen = strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S %z ", tmp);
#else #else
@ -2121,23 +2138,21 @@ static void vm_gettime (moo_t* moo, moo_ntime_t* now)
#elif defined(__OS2__) #elif defined(__OS2__)
xtn_t* xtn = GET_XTN(moo); xtn_t* xtn = GET_XTN(moo);
moo_uint64_t bigsec, bigmsec; ULONG msec, elapsed;
ULONG msec; moo_ntime_t et;
/* TODO: use DosTmrQueryTime() and DosTmrQueryFreq()? */ /* TODO: use DosTmrQueryTime() and DosTmrQueryFreq()? */
DosQuerySysInfo (QSV_MS_COUNT, QSV_MS_COUNT, &msec, MOO_SIZEOF(msec)); /* milliseconds */ DosQuerySysInfo (QSV_MS_COUNT, QSV_MS_COUNT, &msec, MOO_SIZEOF(msec)); /* milliseconds */
/* it must return NO_ERROR */
if (msec < xtn->tc_last) elapsed = (msec < xtn->tc_last)? (MOO_TYPE_MAX(ULONG) - xtn->tc_last + msec + 1): (msec - xtn->tc_last);
{
xtn->tc_overflow++;
bigmsec = ((moo_uint64_t)MOO_TYPE_MAX(ULONG) * xtn->tc_overflow) + msec;
}
else bigmsec = msec;
xtn->tc_last = msec; xtn->tc_last = msec;
bigsec = MOO_MSEC_TO_SEC(bigmsec); et.sec = MOO_MSEC_TO_SEC(elapsed);
bigmsec -= MOO_SEC_TO_MSEC(bigsec); msec = elapsed - MOO_SEC_TO_MSEC(et.sec);
MOO_INIT_NTIME (now, bigsec, MOO_MSEC_TO_NSEC(bigmsec)); et.nsec = MOO_MSEC_TO_NSEC(msec);
MOO_ADD_NTIME (&xtn->tc_last_ret , &xtn->tc_last_ret, &et);
*now = xtn->tc_last_ret;
#elif defined(__DOS__) && (defined(_INTELC32_) || defined(__WATCOMC__)) #elif defined(__DOS__) && (defined(_INTELC32_) || defined(__WATCOMC__))
xtn_t* xtn = GET_XTN(moo); xtn_t* xtn = GET_XTN(moo);
@ -2145,14 +2160,8 @@ static void vm_gettime (moo_t* moo, moo_ntime_t* now)
moo_ntime_t et; moo_ntime_t et;
c = clock(); c = clock();
if (c < xtn->tc_last) elapsed = (c < xtn->tc_last)? (MOO_TYPE_MAX(clock_t) - xtn->tc_last + c + 1): (c - xtn->tc_last);
{ xtn->tc_last = c;
elapsed = MOO_TYPE_MAX(clock_t) - xtn->tc_last + c + 1;
}
else
{
elapsed = c - xtn->tc_last;
}
et.sec = elapsed / CLOCKS_PER_SEC; et.sec = elapsed / CLOCKS_PER_SEC;
#if (CLOCKS_PER_SEC == 100) #if (CLOCKS_PER_SEC == 100)
@ -2167,7 +2176,6 @@ static void vm_gettime (moo_t* moo, moo_ntime_t* now)
# error UNSUPPORTED CLOCKS_PER_SEC # error UNSUPPORTED CLOCKS_PER_SEC
#endif #endif
xtn->tc_last = c;
MOO_ADD_NTIME (&xtn->tc_last_ret , &xtn->tc_last_ret, &et); MOO_ADD_NTIME (&xtn->tc_last_ret , &xtn->tc_last_ret, &et);
*now = xtn->tc_last_ret; *now = xtn->tc_last_ret;
@ -2964,24 +2972,24 @@ static void EXPENTRY os2_wait_for_timer_event (ULONG x)
rc = DosStartTimer(MOO_USEC_TO_MSEC(MOO_TICKER_INTERVAL_USECS), (HSEM)os2_tick_sem, &os2_tick_timer); rc = DosStartTimer(MOO_USEC_TO_MSEC(MOO_TICKER_INTERVAL_USECS), (HSEM)os2_tick_sem, &os2_tick_timer);
if (rc != NO_ERROR) if (rc != NO_ERROR)
{ {
DosCloseEventSem ((HSEM)os2_tick_sem); DosCloseEventSem (os2_tick_sem);
goto done; goto done;
} }
while (!os2_tick_done) while (!os2_tick_done)
{ {
rc = DosWaitEventSem((HSEM)os2_tick_sem, 5000L); rc = DosWaitEventSem(os2_tick_sem, 5000L);
#if 0 #if 0
swproc_all_moos (0); swproc_all_moos (0);
DosResetEventSem ((HSEM)os2_tick_sem, &count); DosResetEventSem (os2_tick_sem, &count);
#else #else
DosResetEventSem ((HSEM)os2_tick_sem, &count); DosResetEventSem (os2_tick_sem, &count);
swproc_all_moos (0); swproc_all_moos (0);
#endif #endif
} }
DosStopTimer (os2_tick_timer); DosStopTimer (os2_tick_timer);
DosCloseEventSem ((HSEM)os2_tick_sem); DosCloseEventSem (os2_tick_sem);
done: done:
os2_tick_timer = NULL; os2_tick_timer = NULL;
@ -3702,7 +3710,7 @@ void moo_ignore_termreq (void)
static EXCEPTIONREGISTRATIONRECORD os2_excrr = { 0 }; static EXCEPTIONREGISTRATIONRECORD os2_excrr = { 0 };
static ULONG _System handle_term ( static ULONG APIENTRY handle_term (
PEXCEPTIONREPORTRECORD p1, PEXCEPTIONREPORTRECORD p1,
PEXCEPTIONREGISTRATIONRECORD p2, PEXCEPTIONREGISTRATIONRECORD p2,
PCONTEXTRECORD p3, PCONTEXTRECORD p3,