[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/tosthreads/system TinyThreadSchedulerP.nc, 1.2, 1.3

Kevin Klues klueska at users.sourceforge.net
Thu Oct 9 23:27:05 PDT 2008


Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/tosthreads/system
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv2762/system

Modified Files:
	TinyThreadSchedulerP.nc 
Log Message:
Optimization to kill the thread quanta timer when one or less threads are active (either stopped or supsended waiting for interrupts)

Index: TinyThreadSchedulerP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tosthreads/system/TinyThreadSchedulerP.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TinyThreadSchedulerP.nc	6 Oct 2008 04:40:02 -0000	1.2
--- TinyThreadSchedulerP.nc	10 Oct 2008 06:27:03 -0000	1.3
***************
*** 58,65 ****
    thread_t* yielding_thread;
    //Number of threads started, and currently capable of running if given the chance
!   uint8_t num_started_threads;
    //Thread queue for keeping track of threads waiting to run
    thread_queue_t ready_queue;
    
    /* switch_threads()
     * This routine swaps the stack and allows a thread to run.
--- 58,74 ----
    thread_t* yielding_thread;
    //Number of threads started, and currently capable of running if given the chance
!   uint8_t num_runnable_threads;
    //Thread queue for keeping track of threads waiting to run
    thread_queue_t ready_queue;
    
+   void task timerTask() {
+     uint8_t temp;
+     atomic temp = num_runnable_threads;
+     if(temp <= 1)
+       call PreemptionAlarm.stop();
+     if(temp > 1)
+       call PreemptionAlarm.startOneShot(TOSTHREAD_PREEMPTION_PERIOD);
+   }
+   
    /* switch_threads()
     * This routine swaps the stack and allows a thread to run.
***************
*** 130,133 ****
--- 139,144 ----
      //if there are no active threads, put the MCU to sleep
      //Then wakeup the TinyOS thread whenever the MCU wakes up again
+     num_runnable_threads--;
+ 	post timerTask();
      sleepWhileIdle();
      interrupt(thread);
***************
*** 142,152 ****
       int i;
       t->state = TOSTHREAD_STATE_INACTIVE;
!      num_started_threads--;
       for(i=0; i<TOSTHREAD_MAX_NUM_THREADS; i++) {
         if(call BitArrayUtils.getBit(t->joinedOnMe, i))
           call ThreadScheduler.wakeupThread(i);
  	 }
-      if(num_started_threads == 1)
-        call PreemptionAlarm.stop();
       signal ThreadCleanup.cleanup[t->id]();
     }
--- 153,162 ----
       int i;
       t->state = TOSTHREAD_STATE_INACTIVE;
!      num_runnable_threads--;
!      post timerTask();
       for(i=0; i<TOSTHREAD_MAX_NUM_THREADS; i++) {
         if(call BitArrayUtils.getBit(t->joinedOnMe, i))
           call ThreadScheduler.wakeupThread(i);
  	 }
       signal ThreadCleanup.cleanup[t->id]();
     }
***************
*** 170,174 ****
    
    event void ThreadSchedulerBoot.booted() {
!     num_started_threads = 0;
      tos_thread = call ThreadInfo.get[TOSTHREAD_TOS_THREAD_ID]();
      tos_thread->id = TOSTHREAD_TOS_THREAD_ID;
--- 180,184 ----
    
    event void ThreadSchedulerBoot.booted() {
!     num_runnable_threads = 0;
      tos_thread = call ThreadInfo.get[TOSTHREAD_TOS_THREAD_ID]();
      tos_thread->id = TOSTHREAD_TOS_THREAD_ID;
***************
*** 194,202 ****
        thread_t* t = (call ThreadInfo.get[id]());
        if(t->state == TOSTHREAD_STATE_INACTIVE) {
-         num_started_threads++;
-         if(num_started_threads == 2)
-           call PreemptionAlarm.startOneShot(TOSTHREAD_PREEMPTION_PERIOD);
          t->state = TOSTHREAD_STATE_READY;
          call ThreadQueue.enqueue(&ready_queue, t);
          return SUCCESS;
        }
--- 204,211 ----
        thread_t* t = (call ThreadInfo.get[id]());
        if(t->state == TOSTHREAD_STATE_INACTIVE) {
          t->state = TOSTHREAD_STATE_READY;
          call ThreadQueue.enqueue(&ready_queue, t);
+         num_runnable_threads++;
+         post timerTask();
          return SUCCESS;
        }
***************
*** 259,262 ****
--- 268,273 ----
        t->state = TOSTHREAD_STATE_READY;
        call ThreadQueue.enqueue(&ready_queue, call ThreadInfo.get[id]());
+       atomic num_runnable_threads++;
+       post timerTask();
        return SUCCESS;
      }



More information about the Tinyos-2-commits mailing list