コード例 #1
0
ファイル: event.c プロジェクト: parai/OpenOSEK
/* |------------------+------------------------------------------------------------| */
EXPORT StatusType WaitEvent ( EventMaskType Mask )
{
	StatusType ercd = E_OK;
    uint8 flgid;
    OS_EXT_VALIDATE((0 == knl_taskindp),E_OS_CALLEVEL);
    OS_EXT_VALIDATE((INVALID_RESOURCE == knl_tcb_resque[knl_curtsk]),E_OS_RESOURCE);
    flgid = knl_tcb_flgid[knl_curtsk];
    OS_EXT_VALIDATE((flgid != INVALID_FLAG),E_OS_ACCESS);

    BEGIN_CRITICAL_SECTION();
    if((knl_fcb_set[flgid] & Mask) == NO_EVENT)
    {
    	knl_fcb_wait[flgid] = Mask;
        knl_tcb_state[knl_curtsk] = WAITING;
        //release internal resource or for Non-Preemtable Task
        ReleaseInternalResource();
        knl_search_schedtsk();
    }
    END_CRITICAL_SECTION();
    //re-get internal resource or for Non-Preemtable task
    GetInternalResource();
OS_VALIDATE_ERROR_EXIT()
    OsErrorProcess1(WaitEvent,mask,Mask);
	return ercd;
}
コード例 #2
0
ファイル: resource.c プロジェクト: parai/OpenOSEK
/* |------------------+------------------------------------------------------------| */
StatusType ReleaseResource ( ResourceType ResID )
{
	StatusType ercd = E_OK;
	OS_EXT_VALIDATE((0 == knl_taskindp),E_OS_CALLEVEL); //add as share resource with ISR was not supported
	OS_EXT_VALIDATE((ResID < cfgOS_S_RES_NUM),E_OS_ID);
	OS_EXT_VALIDATE(knl_tcb_resque[knl_curtsk] == ResID,E_OS_NOFUNC);
    OS_EXT_VALIDATE((knl_rcb_priority[ResID] >= knl_tcb_ipriority[knl_curtsk]),E_OS_ACCESS);

    BEGIN_CRITICAL_SECTION();
    knl_tcb_curpri[knl_curtsk] = knl_rcb_tskpri[ResID];
    // remove it at head
    knl_tcb_resque[knl_curtsk] = knl_rcb_next[ResID];
    knl_rcb_tskpri[ResID] = INVALID_PRIORITY;
    if(knl_tcb_curpri[knl_curtsk] > knl_rdyque.top_pri)
    {
        knl_preempt();
    }
    END_CRITICAL_SECTION();
OS_VALIDATE_ERROR_EXIT()
    OsErrorProcess1(ReleaseResource,resid,ResID);
	return ercd;
}
コード例 #3
0
ファイル: alarm.c プロジェクト: parai/OpenOSEK
EXPORT StatusType SignalCounter(CounterType counter)
{
	AlarmType alarm;
	BEGIN_CRITICAL_SECTION();
	/* here I see the difference between arccore and nxtOSEK.
	   in nxtOSEK, max allowed value allowed for counter and alarm are both the MaxAllowedValue*2,
	   as it has implemented the TicksPerBase. So the method used by nxtOSEK is preferred.
	*/
	knl_ccb_value[counter] = knl_add_ticks(knl_ccb_value[counter],1,knl_ccb_max[counter]*2);
	alarm = knl_ccb_head[counter];
	while(INVALID_ALARM != alarm)
	{
		if(knl_diff_tick(knl_ccb_value[counter],knl_acb_value[alarm],knl_ccb_max[counter]*2)
				> knl_ccb_max[counter])
		{
			break;
		}
		else
		{
			AlarmType next = knl_acb_next[alarm];
			knl_acb_action[alarm]();
			knl_alarm_remove(alarm);
			if(0 != knl_acb_period[alarm])
			{
				knl_acb_value[alarm] = knl_add_ticks(knl_ccb_value[counter],	\
														knl_acb_period[alarm],	\
														knl_ccb_max[counter]*2);
				knl_alarm_insert(alarm);
			}
			else
			{
				knl_acb_value[alarm] = ALARM_STOPPED;
			}
			alarm = next;
		}
	}
	END_CRITICAL_SECTION();
	return E_OK;
}
コード例 #4
0
ファイル: event.c プロジェクト: parai/OpenOSEK
EXPORT StatusType osekSetEvent  ( TaskType TaskID , EventMaskType Mask )
#endif
{
	StatusType ercd = E_OK;
	uint8 flgid ;
	OS_EXT_VALIDATE((TaskID < cfgOS_TASK_NUM),E_OS_ID);
	flgid = knl_tcb_flgid[TaskID];
	OS_EXT_VALIDATE((flgid != INVALID_FLAG),E_OS_ACCESS);
	OS_EXT_VALIDATE((SUSPENDED != knl_tcb_state[TaskID]),E_OS_STATE);

	BEGIN_CRITICAL_SECTION();
	knl_fcb_set[flgid] |= Mask;
	if((knl_fcb_set[flgid] & knl_fcb_wait[flgid]) != NO_EVENT)
	{
		knl_fcb_wait[flgid] = NO_EVENT;
		knl_tcb_state[TaskID] = READY;
		knl_make_runnable(TaskID);
	}
	END_CRITICAL_SECTION();
OS_VALIDATE_ERROR_EXIT()
	OsErrorProcess2(SetEvent,tskid,TaskID,mask,Mask);
	return ercd;
}
コード例 #5
0
ファイル: src.cpp プロジェクト: MiKTeX/miktex
bool DviImpl::FindSource(const char* fileName, int line, DviPosition& position)
{
  CheckCondition();

  BEGIN_CRITICAL_SECTION(dviMutex)
  {
    trace_search->WriteFormattedLine("libdvi", T_("searching src special %d %s"), line, fileName);

    SourceSpecial* pSourceSpecial1Best = nullptr;
    SourceSpecial* pSourceSpecial2Best = nullptr;

    int pageIdx1 = -1;
    int pageIdx2 = -1;

    // get fully qualified path to the directory location of the
    // document
    PathName documentLocation(fqDviFileName);
    documentLocation.RemoveFileSpec();

    // file name relative to the location of the DVI document
    const char* lpszRelFileName;

    // absolute file name
    PathName fqFileName;

    if (Utils::IsAbsolutePath(fileName))
    {
      lpszRelFileName = Utils::GetRelativizedPath(fileName, documentLocation.GetData());
      fqFileName = fileName;
      fqFileName.MakeAbsolute();
    }
    else
    {
      lpszRelFileName = fileName;
      fqFileName = documentLocation;
      fqFileName /= fileName;
      fqFileName.MakeAbsolute();
    }

    //
    // scan the document
    //

    for (int pageIdx = 0; pageIdx < GetNumberOfPages(); ++pageIdx)
    {
      DviPageImpl* dviPage;

      try
      {
        dviPage = reinterpret_cast<DviPageImpl*>(GetLoadedPage(pageIdx));
      }
      catch (const OperationCancelledException&)
      {
        return false;
      }

      if (dviPage == nullptr)
      {
        throw DviPageNotFoundException("", T_("The DVI page could not be found."), MiKTeXException::KVMAP(), MIKTEX_SOURCE_LOCATION());
      }

      AutoUnlockPage autoUnlockPage(dviPage);

      SourceSpecial* pSourceSpecial1 = nullptr;
      SourceSpecial* pSourceSpecial2 = nullptr;

      SourceSpecial* pSourceSpecial;

      for (int j = -1; (pSourceSpecial = dviPage->GetNextSpecial<SourceSpecial>(j)) != nullptr; )
      {
        const char* name = pSourceSpecial->GetFileName();

        // try exact match
        bool nameMatch = (MyPathNameCompare(name, fileName) == 0);

        // try fully qualified file names
        if (!nameMatch)
        {
          PathName fqName;
          if (Utils::IsAbsolutePath(name))
          {
            fqName = name;
            fqName.MakeAbsolute();
          }
          else
          {
            fqName = documentLocation;
            fqName /= name;
            fqName.MakeAbsolute();
          }
          nameMatch = (MyPathNameCompare(fqName, fqFileName) == 0);
        }

        // try relative file names
        if (!nameMatch && lpszRelFileName != nullptr)
        {
          const char* lpszRelName;
          if (!Utils::IsAbsolutePath(name))
          {
            lpszRelName = name;
          }
          else
          {
            lpszRelName = Utils::GetRelativizedPath(name, documentLocation.GetData());
          }
          nameMatch = lpszRelName != nullptr && MyPathNameCompare(lpszRelName, lpszRelFileName) == 0;
        }

        if (!nameMatch)
        {
          continue;
        }

        if (line >= pSourceSpecial->GetLineNum())
        {
          if (pSourceSpecial1 == nullptr || (pSourceSpecial->GetLineNum() > pSourceSpecial1->GetLineNum()))
          {
            pSourceSpecial1 = pSourceSpecial;
          }
        }

        if (line <= pSourceSpecial->GetLineNum())
        {
          if (pSourceSpecial2 == nullptr || (pSourceSpecial->GetLineNum() < pSourceSpecial2->GetLineNum()))
          {
            pSourceSpecial2 = pSourceSpecial;
          }
        }
      }

      if (pSourceSpecial1 != nullptr && pSourceSpecial2 != nullptr)
      {
        pSourceSpecial1Best = pSourceSpecial1;
        pageIdx1 = pageIdx;
        pSourceSpecial2Best = pSourceSpecial2;
        pageIdx2 = pageIdx;
        break;
      }
      else if (pSourceSpecial1 != nullptr
        && (pSourceSpecial1Best == nullptr || (abs(pSourceSpecial1Best->GetLineNum() - line) > abs(pSourceSpecial1->GetLineNum() - line))))
      {
        pSourceSpecial1Best = pSourceSpecial1;
        pageIdx1 = pageIdx;
        pSourceSpecial2Best = nullptr;
        pageIdx2 = -1;
      }
      else if (pSourceSpecial2 != nullptr && (pSourceSpecial2Best == nullptr || (abs(pSourceSpecial2Best->GetLineNum() - line) > abs(pSourceSpecial2->GetLineNum() - line))))
      {
        pSourceSpecial2Best = pSourceSpecial2;
        pageIdx2 = pageIdx;
        pSourceSpecial1Best = nullptr;
        pageIdx1 = -1;
      }
    }

    //
    // evaluate the results
    //

    if (pSourceSpecial1Best == nullptr && pSourceSpecial2Best == nullptr)
    {
      trace_search->WriteLine("libdvi", T_("search failed"));
      return false;
    }

    if (pSourceSpecial1Best == nullptr)
    {
      trace_search->WriteFormattedLine("libdvi", T_("found src2 on page #%d"), pageIdx2);
      trace_search->WriteFormattedLine("libdvi", "   src2 = [%d (%d,%d)]", pSourceSpecial2Best->GetLineNum(), pSourceSpecial2Best->GetX(), pSourceSpecial2Best->GetY());
      position.pageIdx = pageIdx2;
      position.x = pSourceSpecial2Best->GetX();
      position.y = pSourceSpecial2Best->GetY();
    }
    else if (pSourceSpecial2Best == nullptr)
    {
      trace_search->WriteFormattedLine("libdvi", T_("found src1 on page #%d"), pageIdx1);
      trace_search->WriteFormattedLine("libdvi", "   src1 = [%d (%d,%d)]", pSourceSpecial1Best->GetLineNum(), pSourceSpecial1Best->GetX(), pSourceSpecial1Best->GetY());
      position.pageIdx = pageIdx1;
      position.x = pSourceSpecial1Best->GetX();
      position.y = pSourceSpecial1Best->GetY();
    }
    else
    {
      position.pageIdx = pageIdx1;
      trace_search->WriteFormattedLine("libdvi", T_("found src region on page #%d"), position.pageIdx);
      trace_search->WriteFormattedLine("libdvi", "   src1 = [%d (%d,%d)]", pSourceSpecial1Best->GetLineNum(), pSourceSpecial1Best->GetX(), pSourceSpecial1Best->GetY());
      trace_search->WriteFormattedLine("libdvi", "   src2 = [%d (%d,%d)]", pSourceSpecial2Best->GetLineNum(), pSourceSpecial2Best->GetX(), pSourceSpecial2Best->GetY());
      position.x = pSourceSpecial1Best->GetX();
      if (pSourceSpecial2Best->GetLineNum() == pSourceSpecial1Best->GetLineNum())
      {
        position.y = pSourceSpecial1Best->GetY();
      }
      else
      {
        position.y = (pSourceSpecial1Best->GetY()
          + ((line - pSourceSpecial1Best->GetLineNum())
            * (pSourceSpecial2Best->GetY()
              - pSourceSpecial1Best->GetY())
            / (pSourceSpecial2Best->GetLineNum()
              - pSourceSpecial1Best->GetLineNum())));
      }
      trace_search->WriteFormattedLine("libdvi", "   interpolated (x,y) = (%d,%d)", position.x, position.y);
    }

    return true;
  }
  END_CRITICAL_SECTION();
}
コード例 #6
0
ファイル: src.cpp プロジェクト: MiKTeX/miktex
bool DviImpl::GetSource(const DviPosition& pos, PathName& fileName, int* pLineNum)
{
  CheckCondition();
  BEGIN_CRITICAL_SECTION(dviMutex)
  {
    if (pos.pageIdx >= GetNumberOfPages())
    {
      return false;
    }

    DviPageImpl* dviPage = reinterpret_cast<DviPageImpl*>(GetLoadedPage(pos.pageIdx));

    if (dviPage == nullptr)
    {
      throw DviPageNotFoundException("", T_("The DVI page could not be found."), MiKTeXException::KVMAP(), MIKTEX_SOURCE_LOCATION());
    }

    AutoUnlockPage autoUnlockPage(dviPage);

    SourceSpecial* pSourceSpecial1 = nullptr;
    SourceSpecial* pSourceSpecial2 = nullptr;

    int cursorOffset = OFFSET(pos.x, pos.y);

    int src1Offset = 0;
    int src2Offset = 0;

    SourceSpecial* pSourceSpecial;

    // find two adjacent src specials
    for (int j = -1; (pSourceSpecial = dviPage->GetNextSpecial<SourceSpecial>(j)) != nullptr; )
    {
      int srcOffset = OFFSET(pSourceSpecial->GetX(), pSourceSpecial->GetY());
      if (cursorOffset > srcOffset)
      {
        if (pSourceSpecial1 == nullptr || srcOffset > src1Offset)
        {
          pSourceSpecial1 = pSourceSpecial;
          src1Offset = srcOffset;
        }
      }
      else if (cursorOffset < srcOffset)
      {
        if (pSourceSpecial2 == nullptr || srcOffset < src2Offset)
        {
          pSourceSpecial2 = pSourceSpecial;
          src2Offset = srcOffset;
        }
      }
    }

    if (pSourceSpecial1 == nullptr && pSourceSpecial2 == nullptr)
    {
      return false;
    }

    int lineDelta = 0;

    if (pSourceSpecial1 == nullptr)
    {
      pSourceSpecial = pSourceSpecial2;
    }
    else if (pSourceSpecial2 == nullptr)
    {
      pSourceSpecial = pSourceSpecial1;
    }
    else if (MyPathNameCompare(pSourceSpecial1->GetFileName(), pSourceSpecial2->GetFileName()) != 0)
    {
      if (cursorOffset - src1Offset < src2Offset - cursorOffset)
      {
        pSourceSpecial = pSourceSpecial1;
      }
      else
      {
        pSourceSpecial = pSourceSpecial2;
      }
    }
    else
    {
      int d = src2Offset - src1Offset;
      if (d != 0)
      {
        int d1 = cursorOffset - src1Offset;
        int linesbetween
          = (pSourceSpecial2->GetLineNum()
            - pSourceSpecial1->GetLineNum()
            + 1);
        lineDelta = (d1 * linesbetween) / d;
      }
      pSourceSpecial = pSourceSpecial1;
    }
    fileName = pSourceSpecial->GetFileName();
    if (pLineNum != nullptr)
    {
      *pLineNum = pSourceSpecial->GetLineNum() + lineDelta;
    }

    return true;
  }
  END_CRITICAL_SECTION();
}