sys_clock: Fix unsafe tick count usage
The system tick count is a 64 bit quantity that gets updated from interrupt context, meaning that it's dangerously non-atomic and has to be locked. The core kernel clock code did this right. But the value was also exposed to the rest of the universe as a global variable, and virtually nothing else was doing this correctly. Even in the timer ISRs themselves, the interrupts may be themselves preempted (most of our architectures support nested interrupts) by code that wants to set timeouts and inspect system uptime. Define a z_tick_{get,set}() API, eliminate the old variable, and make sure everyone uses the right mechanism. Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
parent
b8ffd9acd6
commit
317178b88f
16 changed files with 105 additions and 100 deletions
|
@ -185,7 +185,32 @@ static inline s64_t __ticks_to_ms(s64_t ticks)
|
|||
* @} end defgroup clock_apis
|
||||
*/
|
||||
|
||||
extern volatile u64_t _sys_clock_tick_count;
|
||||
/**
|
||||
*
|
||||
* @brief Return the lower part of the current system tick count
|
||||
*
|
||||
* @return the current system tick count
|
||||
*
|
||||
*/
|
||||
u32_t z_tick_get_32(void);
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief Return the current system tick count
|
||||
*
|
||||
* @return the current system tick count
|
||||
*
|
||||
*/
|
||||
s64_t z_tick_get(void);
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief Sets the current system tick count
|
||||
*
|
||||
* @param ticks Ticks since system start
|
||||
*
|
||||
*/
|
||||
void z_tick_set(s64_t ticks);
|
||||
|
||||
/* timeouts */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue