|
用来控制挂起时间的。例如你主动调用delay或者阻塞于获取信号量等都会用到这个定时器。截取了一段信号量获取函数中的源码:0 C }7 c! [6 ^) ^1 i3 h
`( f) j: B4 X( k' S7 L
/ start /
- a7 _6 \0 e9 f5 x) nrt_ipc_list_suspend(&(sem->parent.suspend_thread),6 y- A- Z3 w) a6 v+ H9 c0 p1 V3 X
thread,
6 ?: C9 h; n/ _9 u: zsem->parent.parent.flag);
! g. H0 o9 U5 ^2 n* t
& @* V2 t0 O" s7 @: P/* has waiting time, start thread timer */! ^5 J/ b, j3 E8 b0 E' J" q
if (time > 0)! z/ Q0 S+ |, g( I9 U6 k u
{8 a8 R# _ ]* g4 f! ~, ^3 S& S
RT_DEBUG_LOG(RT_DEBUG_IPC, ("set thread:%s to timer list\n",6 t! C% w( K: c
thread->name));
8 C6 x {: {( M# |& U/* reset the timeout of thread timer and start it */
/ ?/ V! T4 m/ Nrt_timer_control(&(thread->thread_timer),# x# n- A9 G3 d+ k2 V! T8 ?$ W
RT_TIMER_CTRL_SET_TIME,
' f' U3 V7 n! U& B&time);* O3 s. @: y, C2 D
rt_timer_start(&(thread->thread_timer));# d. ~# h" G+ j6 y5 e/ Q8 @/ y
}9 k" P% v/ f8 B$ d
/* enable interrupt */
# j' ?" w, [/ w9 R& u, \rt_hw_interrupt_enable(temp);& U+ s0 z& H# b# s4 ~! G
/* do schedule */" x$ D: a! r! \& d0 k
rt_schedule(); rt_ipc_list_suspend(&(sem->parent.suspend_thread),
# b5 Y% I; g4 Z4 d- S* M6 k/ ^thread,
5 ], z9 w X5 c, Vsem->parent.parent.flag); H1 j8 c1 A9 m9 K$ G: V/ q
/* has waiting time, start thread timer */
9 e# Y) G) N! h' mif (time > 0)
" b6 _4 E6 I( J. m9 n{+ e" G" ]* \6 i O9 t* z- r' T- d
RT_DEBUG_LOG(RT_DEBUG_IPC, ("set thread:%s to timer list\n",# V' k$ c( u9 c2 r8 ^- O
thread->name));
6 [" a: @. ?! M1 E3 h/* reset the timeout of thread timer and start it */
1 }6 G* X. L" b/ D! Trt_timer_control(&(thread->thread_timer),
) B4 y5 g* j, n* ~ W: o6 DRT_TIMER_CTRL_SET_TIME,
0 E6 [; V; l6 {8 b&time);
, e6 r* |( |5 N6 @) Brt_timer_start(&(thread->thread_timer));
4 R; {! F2 j- W( q}! |3 a- L; @8 e: l/ f
/* enable interrupt */. T. {, c& } p3 ]3 v, J
rt_hw_interrupt_enable(temp);
6 [4 b! b5 N$ s, u C/* do schedule */
" x. x4 T; v% r& D. F( yrt_schedule();`) a, H8 l$ `! [5 U
|
|