|
|
用来控制挂起时间的。例如你主动调用delay或者阻塞于获取信号量等都会用到这个定时器。截取了一段信号量获取函数中的源码:
) l! }% }) H( a* R) x/ k) d`
9 e4 [- q5 g3 g/ start /4 |# d2 M) }" f% t
rt_ipc_list_suspend(&(sem->parent.suspend_thread),
2 \8 X+ p& B+ rthread,. V- R: P1 T! P' o1 x% I8 m% Z
sem->parent.parent.flag);# C" E) U8 |+ `; g
8 Y4 J R G* A" b! g( k
/* has waiting time, start thread timer */0 [% b! D: O+ P+ j7 J4 {
if (time > 0); ^$ q& _4 [" W8 ?! ?+ e9 c/ i: L
{
$ V$ ^/ N: g! V- W* zRT_DEBUG_LOG(RT_DEBUG_IPC, ("set thread:%s to timer list\n", o( Z" K) E' o# H: W9 Z& Z! ]0 @
thread->name));
7 P- g2 I5 F3 j' P" y3 W! G/* reset the timeout of thread timer and start it */) ` R$ A; @2 B" `$ I
rt_timer_control(&(thread->thread_timer),
. S/ v3 Q0 U, K7 y7 k( |RT_TIMER_CTRL_SET_TIME,
% d+ y1 P2 K0 t) _. m& f3 _&time);9 {& u5 w, P6 W* n( ]* ~/ f
rt_timer_start(&(thread->thread_timer));3 X) [; f+ Y$ ?3 {0 i! u" g
}
0 {' y# n' N) W% M- @: v/* enable interrupt */! G4 l x' G& `3 h, K3 p# s
rt_hw_interrupt_enable(temp);
1 G: H7 n* B8 @- h( z/* do schedule */ A2 L. C8 _+ x
rt_schedule(); rt_ipc_list_suspend(&(sem->parent.suspend_thread),
0 y5 P% w' {( ]. p! dthread,! Q. c/ g& P9 D& P
sem->parent.parent.flag);) a4 b" ~1 C- k0 R" _& Z
/* has waiting time, start thread timer */
& a, [- A M+ g3 s& q5 x& i3 L9 aif (time > 0)( v; q: h6 h* ^6 C
{( ]& }7 p2 R9 n) H: G0 Y
RT_DEBUG_LOG(RT_DEBUG_IPC, ("set thread:%s to timer list\n",
7 w/ G( w" G& L* G4 G# O' n2 Pthread->name));
* s5 Q; X0 ?6 x9 e3 E/* reset the timeout of thread timer and start it */
7 |$ _, Z6 B2 q2 \4 hrt_timer_control(&(thread->thread_timer),
6 `# G& t7 B# O0 q; E8 RRT_TIMER_CTRL_SET_TIME,& v+ R) `1 a2 S; z( V& z( W
&time);
) P; z3 f5 k* u/ |( |' Q# K( vrt_timer_start(&(thread->thread_timer));- J) c! D* @$ S9 B! v o7 L* h
}, ]4 W3 ~3 Q! F+ u) t6 I j
/* enable interrupt */0 |1 M5 U: f* P& f1 Q
rt_hw_interrupt_enable(temp);
) T4 }% x" ?) E' Z. U0 s/* do schedule */9 K1 d7 }7 b( G% c! Y
rt_schedule();`' j! ?4 M1 _% x. i+ H5 P9 U. `
|
|