OpenCores
URL https://opencores.org/ocsvn/plasma/plasma/trunk

Subversion Repositories plasma

[/] [plasma/] [trunk/] [kernel/] [rtos.c] - Diff between revs 146 and 151

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 146 Rev 151
Line 318... Line 318...
 
 
   if(prev == NULL)
   if(prev == NULL)
   {
   {
      thread->nextTimeout = TimeoutHead;
      thread->nextTimeout = TimeoutHead;
      thread->prevTimeout = NULL;
      thread->prevTimeout = NULL;
 
      if(TimeoutHead)
 
         TimeoutHead->prevTimeout = thread;
      TimeoutHead = thread;
      TimeoutHead = thread;
   }
   }
   else
   else
   {
   {
      if(prev->nextTimeout)
      if(prev->nextTimeout)
Line 349... Line 351...
   thread->prevTimeout = NULL;
   thread->prevTimeout = NULL;
}
}
 
 
 
 
/******************************************/
/******************************************/
//Loads a new thread and enabled interrupts
//Loads a new thread 
//Must be called with interrupts disabled
//Must be called with interrupts disabled
//May enable interrupts
 
static void OS_ThreadReschedule(int RoundRobin)
static void OS_ThreadReschedule(int RoundRobin)
{
{
   OS_Thread_t *threadNext, *threadPrev;
   OS_Thread_t *threadNext, *threadPrev;
   int rc;
   int rc;
 
 
Line 366... Line 367...
   }
   }
 
 
   //Determine which thread should run
   //Determine which thread should run
   threadNext = ThreadCurrent;
   threadNext = ThreadCurrent;
   assert(ThreadHead);
   assert(ThreadHead);
   if(ThreadCurrentActive == 0)
   if(ThreadCurrentActive == 0 || ThreadCurrent == NULL)
      threadNext = ThreadHead;
      threadNext = ThreadHead;
   else if(ThreadCurrent->priority < ThreadHead->priority)
   else if(ThreadCurrent->priority < ThreadHead->priority)
      threadNext = ThreadHead;
      threadNext = ThreadHead;
   else if(RoundRobin)
   else if(RoundRobin)
   {
   {
Line 384... Line 385...
   if(threadNext != ThreadCurrent)
   if(threadNext != ThreadCurrent)
   {
   {
      //Swap threads
      //Swap threads
      threadPrev = ThreadCurrent;
      threadPrev = ThreadCurrent;
      ThreadCurrent = threadNext;
      ThreadCurrent = threadNext;
 
      assert(ThreadCurrent);
      if(threadPrev)
      if(threadPrev)
      {
      {
         assert(threadPrev->magic[0] == THREAD_MAGIC); //check stack overflow
         assert(threadPrev->magic[0] == THREAD_MAGIC); //check stack overflow
         //printf("OS_ThreadRescheduleSave(%s)\n", threadPrev->name);
         //printf("OS_ThreadRescheduleSave(%s)\n", threadPrev->name);
         rc = setjmp(threadPrev->env);   //ANSI C call to save registers
         rc = setjmp(threadPrev->env);   //ANSI C call to save registers
         if(rc)
         if(rc)
         {
         {
            //Returned from longjmp()
            //Returned from longjmp()
            OS_CriticalEnd(0xffffffff);  //Must re-enable interrupts!
 
            return;
            return;
         }
         }
      }
      }
      ThreadCurrentActive = 1;
      ThreadCurrentActive = 1;
      //printf("OS_ThreadRescheduleRestore(%s)\n", ThreadCurrent->name);
      //printf("OS_ThreadRescheduleRestore(%s)\n", ThreadCurrent->name);
Line 619... Line 620...
   uint32 state;
   uint32 state;
   OS_Thread_t *thread;
   OS_Thread_t *thread;
   int returnCode=0;
   int returnCode=0;
 
 
   assert(Semaphore);
   assert(Semaphore);
 
   assert(InterruptInside == 0);
   state = OS_CriticalBegin();
   state = OS_CriticalBegin();
   if(--Semaphore->count < 0)
   if(--Semaphore->count < 0)
   {
   {
 
      assert(ThreadCurrent);
      if(Ticks == 0)
      if(Ticks == 0)
      {
      {
         ++Semaphore->count;
         ++Semaphore->count;
         OS_CriticalEnd(state);
         OS_CriticalEnd(state);
         return -1;
         return -1;
Line 1047... Line 1050...
static volatile uint32 IdleCount;
static volatile uint32 IdleCount;
static void OS_IdleThread(void *Arg)
static void OS_IdleThread(void *Arg)
{
{
   (void)Arg;
   (void)Arg;
 
 
 
   //Don't block in the idle thread!
   for(;;)
   for(;;)
   {
   {
      ++IdleCount;
      ++IdleCount;
   }
   }
}
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.