Пример #1
0
int CMyMsgPool::Waite2Committed(unsigned long long index)//这个接口只能被单线程调用
{
	CNPAutoLock lock(m_single_thread);
	m_waitIndex = index;
	//NPLogInfo(("%s,%d",__FUNCTION__,__LINE__));
	EventExSet();
	//NPLogInfo(("%s,%d",__FUNCTION__,__LINE__));
	SemaWait();
	//NPLogInfo(("%s,%d",__FUNCTION__,__LINE__));
	return m_result;
}
Пример #2
0
static void a_enterInterruptlevel(void)
{
  /* synchronize Windows threads */
  MutexWait(windowsThreadSyncMutex_g);
  intlevelCounter_g++;

  /* wait here until it is allowed to run the pico]OS functions */
  if (intlevelCounter_g == 1)
  {
again:
    interruptActive_g = 1;
    barrier();
    while ((blockInterrupt_g != 0) || (taskLockCnt_g != 0))
    {
      interruptWaiting_g = 1;
      if (taskLockCnt_g == 0)
      {
        if (!interruptWaiting_g)
          SemaWait(interruptWaitSem_g);
        interruptWaiting_g = 0;
        break;
      }
      interruptActive_g = 0;
      SemaWait(interruptWaitSem_g);
      interruptActive_g = 1;
    }
/*    assert(taskLockCnt_g == 0); */
    SemaWait(globalSyncSem_g);
/*    assert(taskLockCnt_g == 0); */
    if (taskLockCnt_g != 0)
    {
      /* this is a fast hack to catch a seldom race condition
         on Windows 9x machines */
      SemaSignal(globalSyncSem_g);
      fprintf(stderr, "WARNING: arch_c.c: race condition detected\n");
      goto again;
    }
    interruptExecuting_g = 1;
    assert(taskLockCnt_g == 0);
  }
}
Пример #3
0
void p_pos_startFirstContext(void)
{
  TASKPRIV_t firsttask;

  /* Set this thread to high priority. This thread will do the timer IRQ. */
  SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);

  /* Start the first pico]OS task (=first context). */
  SemaWait(globalSyncSem_g);
  p_pos_globalUnlock(-1);
  firsttask = GETTASKPRIV(posCurrentTask_g);
  a_createThisTask(firsttask);
  SemaSignal(globalSyncSem_g);

  /* OK. We continue with doing the timer interrupt. */
  a_initTimer();
  a_timerTask();
}
Пример #4
0
static void a_timerTask(void)
{
  for(;;)
  {
    /* wait for the timer event */
    if (timerEvent_g != NULL)
    {
      Sleep(500/HZ);
      SemaWait(timerEvent_g);
    }
    else
    {
      Sleep(1000/HZ);
    }

    /* execute the timer interrupt */
    callInterruptHandler( c_pos_timerInterrupt );
  }
}
Пример #5
0
static void do_assert(const char* file, int line)
{
  TASKPRIV_t  thistask = GETTASKPRIV(posCurrentTask_g);
  TASKPRIV_t  nexttask = GETTASKPRIV(posNextTask_g);

  fprintf(stderr, "\n\nASSERTION FAILED:  %s, line %i\n\n", file, line);

  fprintf(stderr, "taskLockCnt_g        = %i\n", taskLockCnt_g);
  fprintf(stderr, "blockInterrupt_g     = %i\n", blockInterrupt_g);
  fprintf(stderr, "interruptWaiting_g   = %i\n", interruptWaiting_g);
  fprintf(stderr, "interruptActive_g    = %i\n", interruptActive_g);
  fprintf(stderr, "interruptExecuting_g = %i\n\n", interruptExecuting_g);

#ifdef POS_DEBUGHELP
  fprintf(stderr, "thistask: name       = %s\n", posCurrentTask_g->deb.name);
  fprintf(stderr, "thistask: deb_state  = %i\n", posCurrentTask_g->deb.state);
#else
  fprintf(stderr, "thistask: handle     = %08x\n", (unsigned int)posCurrentTask_g);
#endif
#if SYS_TASKSTATE != 0
  fprintf(stderr, "thistask: pico_state = %i\n", posCurrentTask_g->state);
#endif
  fprintf(stderr, "thistask: arch_state = %i\n", thistask->state);
  fprintf(stderr, "thistask: blockIntFl = %i\n", thistask->blockIntFlag);

  if (thistask != nexttask)
  {
#ifdef POS_DEBUGHELP
    fprintf(stderr, "\nnexttask: name       = %s\n", posNextTask_g->deb.name);
    fprintf(stderr, "nexttask: deb_state  = %i\n", posNextTask_g->deb.state);
#else
    fprintf(stderr, "\nnexttask: handle     = %08x\n", (unsigned int)posNextTask_g);
#endif
#if SYS_TASKSTATE != 0
    fprintf(stderr, "nexttask: pico_state = %i\n", posNextTask_g->state);
#endif
    fprintf(stderr, "nexttask: arch_state = %i\n", nexttask->state);
    fprintf(stderr, "nexttask: blockIntFl = %i\n", nexttask->blockIntFlag);
  }

  for(;;) { SemaWait(globalSyncSem_g); }
}
Пример #6
0
void p_pos_idleTaskHook(void)
{
  /* the idle task gives of processing time here */
  cpuIdleFlag_g = 1;
  SemaWait(idleTaskSuspendSem_g);
}
Пример #7
0
void p_pos_softContextSwitch(void)
{
  TASKPRIV_t  thistask = GETTASKPRIV(posCurrentTask_g);
  TASKPRIV_t  nexttask = GETTASKPRIV(posNextTask_g);
  TSTATE_t    state = thistask->state;

  assert(interruptExecuting_g == 0);
  assert(GetCurrentThreadId() == thistask->ownTaskID);
  assert(thistask != nexttask);
  assert(taskLockCnt_g != 0);

  /* wake the idle task
     (quick-and-dirty to get things working as expected) */
  if (cpuIdleFlag_g != 0)
  {
    cpuIdleFlag_g = 0;
    SemaSignal(idleTaskSuspendSem_g);
  }

  /* swap context variable */
  posCurrentTask_g = posNextTask_g;

  /* start next task */
  if (nexttask->state == task_exist)
  {
    SemaSignal(nexttask->suspendSema);
  }
  else
  if (nexttask->state == task_interrupted)
  {
    Sleep(0);
    SemaWait(globalSyncSem_g);
    assert(taskLockCnt_g == 1);
    blockInterrupt_g = nexttask->blockIntFlag;
    nexttask->state = task_exist;
    p_pos_globalUnlock(-1); 
    assert( ResumeThread(nexttask->ownTaskHandle) == 1 );
    SemaSignal(globalSyncSem_g);
  }
  else
  if (nexttask->state == task_mustcreate)
  {
    SemaWait(globalSyncSem_g);
    assert(taskLockCnt_g == 1);
    p_pos_globalUnlock(-1);
    a_createThisTask(nexttask);
    SemaSignal(globalSyncSem_g);
  }
  else assert(0);

  /* suspend current task */
  if (state == task_exist)
  {
    SemaWait(thistask->suspendSema);
  }
  else
  if (state == task_mustquit)
  {
    a_quitThisTask(thistask);
  }
  else assert(0);

  assert(taskLockCnt_g != 0);
}
Пример #8
0
void p_pos_assert(const char* text, const char *file, int line)
{
  fprintf(stderr, "\n\n-- ASSERTION FAILED:\n\n\"%s\"\n\nfile %s, line %i\n\n",
                  text, file, line);
  for(;;) { SemaWait(globalSyncSem_g); }
}