diff options
| author | xph <[email protected]> | 2020-04-09 16:35:28 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-04-09 16:35:28 +0800 |
| commit | ca7f01d79b3e0a997c771cec298e4ebd65b75809 (patch) | |
| tree | 3d2c48aae7203b14038ba7b98b500b5343ed7f2a /src/clock.c | |
| parent | f763f8e7284b0492c5a65ad0abf94ee1963d7dcc (diff) | |
| parent | baa3145bfe61b3330b6a160523cc5470fa5db3a7 (diff) | |
Merge pull request #1 from RT-Thread/master
sync rtt
Diffstat (limited to 'src/clock.c')
| -rw-r--r-- | src/clock.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/clock.c b/src/clock.c index 651465e0a8..97a09ddeaf 100644 --- a/src/clock.c +++ b/src/clock.c @@ -12,17 +12,20 @@ * 2010-05-20 Bernard fix the tick exceeds the maximum limits * 2010-07-13 Bernard fix rt_tick_from_millisecond issue found by kuronca * 2011-06-26 Bernard add rt_tick_set function. + * 2018-11-22 Jesven add per cpu tick */ #include <rthw.h> #include <rtthread.h> +#ifdef RT_USING_SMP +#define rt_tick rt_cpu_index(0)->tick +#else static rt_tick_t rt_tick = 0; - -extern void rt_timer_check(void); +#endif /** - * This function will init system tick and set it to zero. + * This function will initialize system tick and set it to zero. * @ingroup SystemInit * * @deprecated since 1.1.0, this function does not need to be invoked @@ -71,7 +74,11 @@ void rt_tick_increase(void) struct rt_thread *thread; /* increase the global tick */ +#ifdef RT_USING_SMP + rt_cpu_self()->tick ++; +#else ++ rt_tick; +#endif /* check time slice */ thread = rt_thread_self(); @@ -82,6 +89,8 @@ void rt_tick_increase(void) /* change to initialized tick */ thread->remaining_tick = thread->init_tick; + thread->stat |= RT_THREAD_STAT_YIELD; + /* yield */ rt_thread_yield(); } @@ -100,15 +109,20 @@ void rt_tick_increase(void) * * @return the calculated tick */ -int rt_tick_from_millisecond(rt_int32_t ms) +rt_tick_t rt_tick_from_millisecond(rt_int32_t ms) { - int tick; + rt_tick_t tick; if (ms < 0) - tick = RT_WAITING_FOREVER; + { + tick = (rt_tick_t)RT_WAITING_FOREVER; + } else - tick = (RT_TICK_PER_SECOND * ms + 999) / 1000; - + { + tick = RT_TICK_PER_SECOND * (ms / 1000); + tick += (RT_TICK_PER_SECOND * (ms % 1000) + 999) / 1000; + } + /* return the calculated tick */ return tick; } |
