SLIDE 16 What Really Happens With Tasks
The Foundation in the Scheduler
command void Scheduler . i n i t ( ) { atomic { memset ( ( void ∗) m next , NO TASK, s i z e o f ( m next ) ) ; m head = NO TASK; m t a i l = NO TASK; } } command void Scheduler . taskLoop ( ) { f o r ( ; ; ) { u i n t 8 t nextTask ; atomic { while (( nextTask=popTask ( ) ) == NO TASK) { c a l l McuSleep . s l e e p ( ) ; } } s i g n a l TaskBasic . runTask [ nextTask ] ( ) ; } }
We see that every synchronous execution in TinyOS is based on a task.
Martin Perner TinyOS Part 2 May 22, 2017 46
What Really Happens With Tasks
Data-Structure usage
async command e r r o r t TaskBasic . postTask [ u i n t 8 t i d ] ( ) { atomic{ return pushTask ( i d ) ? SUCCESS : EBUSY; } } bool pushTask ( u i n t 8 t i d ){ i f ( ! i s W a i t i n g ( i d ) ) { i f ( m head== NO TASK) { m head=i d ; m t a i l=i d ; } e l s e { m next [ m t a i l ]= i d ; m t a i l=i d ; } return TRUE; } e l s e { return FALSE ; } } Martin Perner TinyOS Part 2 May 22, 2017 47
Threads
Deprecated!
As there was no one willing to maintain threads, they have been deprecated in the current TinyOS development version. Thread Based Priority Queues using Preemptive Jobs
Bigger Not that easy “Slow”
Platform independent part:
Thread Queue Thread Thread context
Platform dependent part:
the “real” context switching
Martin Perner TinyOS Part 2 May 22, 2017 48