Esempio n. 1
0
/**
 * @brief
 * 初期化を行います。
 *
 * @param pContext
 * I4C3Dモジュールのコンテキストのポインタ。
 *
 * @returns
 * 初期化に成功した場合にはTRUE、失敗した場合にはFALSEを返します。
 *
 * I4C3Dモジュールの初期化を行います。
 * プロセッサ監視系のスレッドの初期化および主要処理系のスレッドの初期化を行います。
 *
 * @see
 * InitializeProcessorContext() | InitializeMainContext()
 */
BOOL I4C3DCore::Initialize(I4C3DContext* pContext)
{
    pContext->processorContext.bIsBusy = FALSE;
    //if ( !InitializeProcessorContext(pContext) ) {
    //	return FALSE;
    //}
    if ( !InitializeMainContext(pContext) ) {
        return FALSE;
    }
    return TRUE;
}
Esempio n. 2
0
/**
* This function re-schedules thread. Here, @removeRunningThread
* is specified, it will remove running thread from list (i.e terminating it.)
* If there is no thread in any queue, as a result of terminating the thread, it will
* switch to main context.
**/
static void ReScheduleThreads(int removeRunningThread) {

  int queue;
  int runningQueue;

  ThreadBlock * currentRunningThread = GetCurrentlyRunningThread(&runningQueue);

  if(removeRunningThread && currentRunningThread != NULL) {
    RemoveThreadBlockFromList(&uThreadContext->queueHeads[runningQueue],currentRunningThread);
  }

  ThreadBlock * threadBlock = GetNextReadyThread(&queue);

  if(threadBlock == NULL) {
    uThreadContext->currentRunningQueue = QUEUE_UNDEFINED;
    setcontext(uThreadContext->mainContext);
    return;
  }

   // Don't need to do anything, if this is the only thread running.
  if(threadBlock == currentRunningThread) {
    return;
  }

   // This case occurs, when there is no thread in any queues,
   // And main thread has scheduled first thread.
  if(uThreadContext->currentRunningQueue == QUEUE_UNDEFINED) {
    uThreadContext->currentRunningQueue = queue;
    uThreadContext->queueHeads[queue] = threadBlock;
    InitializeMainContext();

    threadBlock->status = STATUS_RUNNING;

    swapcontext(uThreadContext->mainContext,threadBlock->context);
  } else {
    uThreadContext->currentRunningQueue = queue;
    uThreadContext->queueHeads[queue] = threadBlock;

    threadBlock->status = STATUS_RUNNING;
    currentRunningThread->status = STATUS_READY;

    swapcontext(currentRunningThread->context,threadBlock->context);
  }
}