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

Kevin Klues klueska at users.sourceforge.net
Tue Oct 21 20:22:29 PDT 2008


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

Modified Files:
	TinyThreadSchedulerP.nc 
Log Message:
bug in adding compile time directive to preemption timer separation.  Now fixed

Index: TinyThreadSchedulerP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tosthreads/system/TinyThreadSchedulerP.nc,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** TinyThreadSchedulerP.nc	21 Oct 2008 20:05:54 -0000	1.5
--- TinyThreadSchedulerP.nc	22 Oct 2008 03:22:27 -0000	1.6
***************
*** 62,75 ****
    thread_queue_t ready_queue;
    
! #ifdef TOSTHREADS_TIMER_OPTIMIZATION   
!   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);
    }
- #endif
    
    /* switch_threads()
--- 62,73 ----
    thread_queue_t ready_queue;
    
!   void task alarmTask() {
      uint8_t temp;
      atomic temp = num_runnable_threads;
      if(temp <= 1)
        call PreemptionAlarm.stop();
!     else if(temp > 1)
        call PreemptionAlarm.startOneShot(TOSTHREAD_PREEMPTION_PERIOD);
    }
    
    /* switch_threads()
***************
*** 101,105 ****
        bool mt;
        atomic mt = (call ThreadQueue.isEmpty(&ready_queue) == TRUE);
!       if(!mt || tos_thread->state == TOSTHREAD_STATE_READY) break;
        call McuSleep.sleep();
      }
--- 99,103 ----
        bool mt;
        atomic mt = (call ThreadQueue.isEmpty(&ready_queue) == TRUE);
!       if(!mt) break;
        call McuSleep.sleep();
      }
***************
*** 113,117 ****
    void scheduleNextThread() {
      if(tos_thread->state == TOSTHREAD_STATE_READY)
!       current_thread = tos_thread;
      else
        current_thread = call ThreadQueue.dequeue(&ready_queue);
--- 111,115 ----
    void scheduleNextThread() {
      if(tos_thread->state == TOSTHREAD_STATE_READY)
!       current_thread = call ThreadQueue.remove(&ready_queue, tos_thread);
      else
        current_thread = call ThreadQueue.dequeue(&ready_queue);
***************
*** 141,147 ****
      //if there are no active threads, put the MCU to sleep
      //Then wakeup the TinyOS thread whenever the MCU wakes up again
!     #ifdef TOSTHREADS_TIMER_OPTIMIZATION   
        num_runnable_threads--;
! 	  post timerTask();
  	#endif
      sleepWhileIdle();
--- 139,145 ----
      //if there are no active threads, put the MCU to sleep
      //Then wakeup the TinyOS thread whenever the MCU wakes up again
!     #ifdef TOSTHREADS_TIMER_OPTIMIZATION
        num_runnable_threads--;
! 	  post alarmTask();    
  	#endif
      sleepWhileIdle();
***************
*** 157,168 ****
      int i;
      t->state = TOSTHREAD_STATE_INACTIVE;
!     #ifdef TOSTHREADS_TIMER_OPTIMIZATION        
!       num_runnable_threads--;
!       post timerTask();
!     #endif
      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]();
    }
--- 155,169 ----
      int i;
      t->state = TOSTHREAD_STATE_INACTIVE;
!     num_runnable_threads--;
      for(i=0; i<TOSTHREAD_MAX_NUM_THREADS; i++) {
        if(call BitArrayUtils.getBit(t->joinedOnMe, i))
          call ThreadScheduler.wakeupThread(i);
      }
+     #ifdef TOSTHREADS_TIMER_OPTIMIZATION
+ 	  post alarmTask();    
+ 	#else
+       if(num_runnable_threads == 1)
+         call PreemptionAlarm.stop();
+     #endif
      signal ThreadCleanup.cleanup[t->id]();
    }
***************
*** 210,219 ****
        thread_t* t = (call ThreadInfo.get[id]());
        if(t->state == TOSTHREAD_STATE_INACTIVE) {
          t->state = TOSTHREAD_STATE_READY;
          call ThreadQueue.enqueue(&ready_queue, t);
-         #ifdef TOSTHREADS_TIMER_OPTIMIZATION   
-           num_runnable_threads++;
-           post timerTask();
-         #endif
          return SUCCESS;
        }
--- 211,223 ----
        thread_t* t = (call ThreadInfo.get[id]());
        if(t->state == TOSTHREAD_STATE_INACTIVE) {
+         num_runnable_threads++;
+         #ifdef TOSTHREADS_TIMER_OPTIMIZATION
+           post alarmTask();
+         #else 
+           if(num_runnable_threads == 2)
+             call PreemptionAlarm.startOneShot(TOSTHREAD_PREEMPTION_PERIOD);
+         #endif
          t->state = TOSTHREAD_STATE_READY;
          call ThreadQueue.enqueue(&ready_queue, t);
          return SUCCESS;
        }
***************
*** 275,285 ****
      if((t->state) == TOSTHREAD_STATE_SUSPENDED) {
        t->state = TOSTHREAD_STATE_READY;
!         if(t != tos_thread) {
!           call ThreadQueue.enqueue(&ready_queue, call ThreadInfo.get[id]());
!           #ifdef TOSTHREADS_TIMER_OPTIMIZATION   
!             atomic num_runnable_threads++;
!             post timerTask();
!           #endif
!         }
        return SUCCESS;
      }
--- 279,287 ----
      if((t->state) == TOSTHREAD_STATE_SUSPENDED) {
        t->state = TOSTHREAD_STATE_READY;
!       call ThreadQueue.enqueue(&ready_queue, call ThreadInfo.get[id]());
!       #ifdef TOSTHREADS_TIMER_OPTIMIZATION
!         atomic num_runnable_threads++;
!         post alarmTask();
!       #endif
        return SUCCESS;
      }
***************
*** 312,314 ****
    }
  }
- 
--- 314,315 ----



More information about the Tinyos-2-commits mailing list