Skip to content

Commit

Permalink
Remove "local time" stuff (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Feb 16, 2018
1 parent a171355 commit 13cb983
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 71 deletions.
31 changes: 4 additions & 27 deletions src/CLR/Core/CLR_RT_HeapBlock_Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,16 @@ void CLR_RT_HeapBlock_Timer::Reschedule()
if((m_flags & CLR_RT_HeapBlock_Timer::c_Recurring ) &&
(m_flags & CLR_RT_HeapBlock_Timer::c_EnabledTimer) )
{
CLR_INT64 cmp = (m_flags & CLR_RT_HeapBlock_Timer::c_AbsoluteTimer) ? g_CLR_RT_ExecutionEngine.m_currentLocalTime : g_CLR_RT_ExecutionEngine.m_currentMachineTime;
CLR_INT64 expire = m_timeLastExpiration + m_timeFrequency;

//
// Normally, adding the 'timeFrequency' will put the expiration in the future.
//
// If we fall back too much, we need to compute the next expiration in the future, to avoid an avalanche effect.
//
if(expire < cmp)
if(expire < g_CLR_RT_ExecutionEngine.m_currentMachineTime)
{
expire = cmp - ((cmp - expire) % m_timeFrequency) + m_timeFrequency;
expire = g_CLR_RT_ExecutionEngine.m_currentMachineTime - ((g_CLR_RT_ExecutionEngine.m_currentMachineTime - expire) % m_timeFrequency) + m_timeFrequency;
}

m_timeExpire = expire; CLR_RT_ExecutionEngine::InvalidateTimerCache();
Expand Down Expand Up @@ -237,21 +236,16 @@ HRESULT CLR_RT_HeapBlock_Timer::ConfigureObject( CLR_RT_StackFrame& stack, CLR_U

if(anyChange)
{
SYSTEMTIME systemTime; HAL_Time_ToSystemTime( g_CLR_RT_ExecutionEngine.m_currentLocalTime, &systemTime );
SYSTEMTIME systemTime; HAL_Time_ToSystemTime( g_CLR_RT_ExecutionEngine.m_currentMachineTime, &systemTime );

timer->m_flags |= anyChange | (CLR_RT_HeapBlock_Timer::c_AbsoluteTimer | CLR_RT_HeapBlock_Timer::c_EnabledTimer);
timer->m_flags |= anyChange | CLR_RT_HeapBlock_Timer::c_EnabledTimer;

timer->AdjustNextFixedExpire( systemTime, true );
}
else
{
flags |= CLR_RT_HeapBlock_Timer::c_ACTION_Change;
}

if(flags & CLR_RT_HeapBlock_Timer::c_INPUT_Absolute)
{
timer->m_flags |= CLR_RT_HeapBlock_Timer::c_AbsoluteTimer;
}
}

if(flags & CLR_RT_HeapBlock_Timer::c_ACTION_Destroy)
Expand All @@ -268,8 +262,6 @@ HRESULT CLR_RT_HeapBlock_Timer::ConfigureObject( CLR_RT_StackFrame& stack, CLR_U

if(flags & CLR_RT_HeapBlock_Timer::c_INPUT_Int32)
{
if((timer->m_flags & CLR_RT_HeapBlock_Timer::c_AbsoluteTimer) != 0) NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER);

timer->m_timeExpire = args[ 0 ].NumericByRef().s4;
timer->m_timeFrequency = args[ 1 ].NumericByRef().s4;

Expand All @@ -280,8 +272,6 @@ HRESULT CLR_RT_HeapBlock_Timer::ConfigureObject( CLR_RT_StackFrame& stack, CLR_U
{
CLR_INT64* pVal;

if((timer->m_flags & CLR_RT_HeapBlock_Timer::c_AbsoluteTimer) != 0) NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER);

pVal = Library_corlib_native_System_TimeSpan::GetValuePtr( args[ 0 ] ); FAULT_ON_NULL(pVal);
if (*pVal == -c_TickPerMillisecond) timer->m_timeExpire = TIMEOUT_INFINITE;
else timer->m_timeExpire = *pVal;
Expand All @@ -290,24 +280,11 @@ HRESULT CLR_RT_HeapBlock_Timer::ConfigureObject( CLR_RT_StackFrame& stack, CLR_U
if (*pVal == -c_TickPerMillisecond) timer->m_timeFrequency = TIMEOUT_INFINITE;
else timer->m_timeFrequency = *pVal;
}
else if(flags & CLR_RT_HeapBlock_Timer::c_INPUT_Absolute)
{
CLR_INT64* pVal;

if((timer->m_flags & CLR_RT_HeapBlock_Timer::c_AbsoluteTimer) == 0) NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER);

pVal = Library_corlib_native_System_DateTime::GetValuePtr( args[ 0 ] ); FAULT_ON_NULL(pVal); timer->m_timeExpire = *pVal;
pVal = Library_corlib_native_System_TimeSpan::GetValuePtr( args[ 1 ] ); FAULT_ON_NULL(pVal); timer->m_timeFrequency = *pVal;
}

if(timer->m_timeExpire == TIMEOUT_INFINITE)
{
timer->m_flags &= ~CLR_RT_HeapBlock_Timer::c_EnabledTimer;
}
else if((flags & CLR_RT_HeapBlock_Timer::c_INPUT_Absolute) )
{
timer->m_flags |= CLR_RT_HeapBlock_Timer::c_EnabledTimer;
}
else
{
if(flags & CLR_RT_HeapBlock_Timer::c_INPUT_Int32) timer->m_timeExpire *= TIME_CONVERSION__TO_MILLISECONDS;
Expand Down
48 changes: 9 additions & 39 deletions src/CLR/Core/Execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ HRESULT CLR_RT_ExecutionEngine::ExecutionEngine_Initialize()
// int m_iDebugger_Conditions;
//
// CLR_INT64 m_currentMachineTime;
// CLR_INT64 m_currentLocalTime;
// UNDONE: FIXME
// m_lastTimeZoneOffset = Time_GetTimeZoneOffset();// CLR_INT32 m_lastTimeZoneOffset;

// CLR_INT64 m_currentNextActivityTime;
m_timerCache = false; // bool m_timerCache;
Expand Down Expand Up @@ -2376,7 +2373,7 @@ void CLR_RT_ExecutionEngine::ProcessTimeEvent( CLR_UINT32 event )

// UNDO FORCE UpdateTime();

HAL_Time_ToSystemTime( m_currentLocalTime, &systemTime );
HAL_Time_ToSystemTime( m_currentMachineTime, &systemTime );

NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_Timer,timer,m_timers)
{
Expand Down Expand Up @@ -2408,14 +2405,13 @@ void CLR_RT_ExecutionEngine::InvalidateTimerCache()

//--//--//

bool CLR_RT_ExecutionEngine::IsTimeExpired( const CLR_INT64& timeExpire, CLR_INT64& timeoutMin, bool fAbsolute )
bool CLR_RT_ExecutionEngine::IsTimeExpired( const CLR_INT64& timeExpire, CLR_INT64& timeoutMin )
{
NATIVE_PROFILE_CLR_CORE();
CLR_INT64 cmp = (fAbsolute ? m_currentLocalTime : m_currentMachineTime);

if(timeExpire <= cmp) return true;
if(timeExpire <= m_currentMachineTime) return true;

CLR_INT64 diff = timeExpire - cmp;
CLR_INT64 diff = timeExpire - m_currentMachineTime;

if(diff < timeoutMin)
{
Expand Down Expand Up @@ -2449,7 +2445,7 @@ void CLR_RT_ExecutionEngine::CheckTimers( CLR_INT64& timeoutMin )
if(timer->m_flags & CLR_RT_HeapBlock_Timer::c_EnabledTimer)
{
CLR_INT64 expire = timer->m_timeExpire;
if(IsTimeExpired( expire, timeoutMin, (timer->m_flags & CLR_RT_HeapBlock_Timer::c_AbsoluteTimer) != 0 ))
if(IsTimeExpired( expire, timeoutMin ))
{
#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING)
if(CLR_EE_DBG_IS_NOT( PauseTimers ))
Expand Down Expand Up @@ -2489,7 +2485,7 @@ void CLR_RT_ExecutionEngine::CheckThreads( CLR_INT64& timeoutMin, CLR_RT_DblLink
// Check events.
//
expire = th->m_waitForEvents_Timeout;
if(IsTimeExpired( expire, timeoutMin, false ))
if(IsTimeExpired( expire, timeoutMin ))
{
th->m_waitForEvents_Timeout = TIMEOUT_INFINITE;

Expand All @@ -2505,7 +2501,7 @@ void CLR_RT_ExecutionEngine::CheckThreads( CLR_INT64& timeoutMin, CLR_RT_DblLink

if(wait)
{
if(IsTimeExpired( wait->m_timeExpire, timeoutMin, false ))
if(IsTimeExpired( wait->m_timeExpire, timeoutMin ))
{
th->m_waitForObject_Result = CLR_RT_Thread::TH_WAIT_RESULT_TIMEOUT;

Expand All @@ -2521,7 +2517,7 @@ void CLR_RT_ExecutionEngine::CheckThreads( CLR_INT64& timeoutMin, CLR_RT_DblLink
{
NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_LockRequest,req,lock->m_requests)
{
if(IsTimeExpired( req->m_timeExpire, timeoutMin, false ))
if(IsTimeExpired( req->m_timeExpire, timeoutMin ))
{
CLR_RT_SubThread* sth = req->m_subthreadWaiting;

Expand All @@ -2541,7 +2537,7 @@ void CLR_RT_ExecutionEngine::CheckThreads( CLR_INT64& timeoutMin, CLR_RT_DblLink
{
if(sth->m_timeConstraint != TIMEOUT_INFINITE)
{
if(IsTimeExpired( s_compensation.Adjust( sth->m_timeConstraint ), timeoutMin, false ))
if(IsTimeExpired( s_compensation.Adjust( sth->m_timeConstraint ), timeoutMin ))
{
(void)Library_corlib_native_System_Exception::CreateInstance( th->m_currentException, g_CLR_RT_WellKnownTypes.m_ConstraintException, S_OK, th->CurrentFrame() );

Expand Down Expand Up @@ -3502,32 +3498,6 @@ void CLR_RT_ExecutionEngine::UpdateTime()
NATIVE_PROFILE_CLR_CORE();

m_currentMachineTime = HAL_Time_CurrentTime();
// FIXME time is now UTC...
m_currentLocalTime = HAL_Time_CurrentTime();

/// Did timezone or daylight offset got adjusted? If yes make some adjustments in timers too.
CLR_INT32 timeZoneOffset = 0;//// FIXME time is now UTC...Time_GetTimeZoneOffset();

if(timeZoneOffset != m_lastTimeZoneOffset)
{
SYSTEMTIME systemTime;

m_lastTimeZoneOffset = timeZoneOffset;
HAL_Time_ToSystemTime( m_currentLocalTime, &systemTime );

NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_Timer,timer,m_timers)
{
if(timer->m_flags & CLR_RT_HeapBlock_Timer::c_EnabledTimer)
{
if(timer->m_flags & CLR_RT_HeapBlock_Timer::c_AnyChange)
{
timer->AdjustNextFixedExpire( systemTime, false );
}
}
}
NANOCLR_FOREACH_NODE_END();
}

}

CLR_UINT32 CLR_RT_ExecutionEngine::WaitSystemEvents( CLR_UINT32 powerLevel, CLR_UINT32 events, CLR_INT64 timeExpire )
Expand Down
4 changes: 1 addition & 3 deletions src/CLR/Include/nanoCLR_Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -2900,9 +2900,7 @@ struct CLR_RT_ExecutionEngine
//--//

CLR_INT64 m_currentMachineTime;
CLR_INT64 m_currentLocalTime;
CLR_INT64 m_startTime;
CLR_INT32 m_lastTimeZoneOffset;
CLR_INT64 m_currentNextActivityTime;
bool m_timerCache;
CLR_INT64 m_timerCacheNextTimeout;
Expand Down Expand Up @@ -3072,7 +3070,7 @@ struct CLR_RT_ExecutionEngine

//--//

bool IsTimeExpired( const CLR_INT64& timeExpire, CLR_INT64& timeoutMin, bool fAbsolute );
bool IsTimeExpired( const CLR_INT64& timeExpire, CLR_INT64& timeoutMin );

bool IsThereEnoughIdleTime( CLR_UINT32 expectedMsec );

Expand Down
2 changes: 0 additions & 2 deletions src/CLR/Include/nanoCLR_Runtime__HeapBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -1752,10 +1752,8 @@ struct CLR_RT_HeapBlock_Timer : public CLR_RT_ObjectToEvent_Destination // EVENT

static const CLR_UINT32 c_INPUT_Int32 = 0x00100000;
static const CLR_UINT32 c_INPUT_TimeSpan = 0x00200000;
static const CLR_UINT32 c_INPUT_Absolute = 0x00400000;

static const CLR_UINT32 c_UNUSED_10000000 = 0x10000000;
static const CLR_UINT32 c_AbsoluteTimer = 0x20000000;
static const CLR_UINT32 c_Recurring = 0x40000000;
static const CLR_UINT32 c_EnabledTimer = 0x80000000;

Expand Down

0 comments on commit 13cb983

Please sign in to comment.