mirror of
https://github.com/elua/elua.git
synced 2025-01-08 20:56:17 +08:00
Reorder assignments in cmn_systimer_get() to avoid race.
Before, it was possible for the system timer counter to wrap from high to low after its value had been read but before the value of cmn_systimer_counter was read and so the resulting sum of those values would be too large. By reordering the assignments, we can now detect if cmn_systimer_counter has been advanced while reading the system timer counter value and, if so, repeat the assignments to ensure consistent values.
This commit is contained in:
parent
e11180bc75
commit
e9f23cc33f
@ -425,12 +425,12 @@ timer_data_type cmn_systimer_get(void)
|
||||
{
|
||||
u64 tempsys, tempcnt, crtsys;
|
||||
|
||||
tempcnt = platform_timer_sys_raw_read();
|
||||
tempsys = cmn_systimer_counter;
|
||||
tempcnt = platform_timer_sys_raw_read();
|
||||
while( ( crtsys = cmn_systimer_counter ) != tempsys )
|
||||
{
|
||||
tempcnt = platform_timer_sys_raw_read();
|
||||
tempsys = crtsys;
|
||||
tempcnt = platform_timer_sys_raw_read();
|
||||
}
|
||||
crtsys += tempcnt / cmn_systimer_ticks_for_us;
|
||||
if( crtsys > PLATFORM_TIMER_SYS_MAX ) // timer overflow
|
||||
|
Loading…
x
Reference in New Issue
Block a user