Example #1
0
void Plan::runCompletionTasks(const AbstractLocker&)
{
    ASSERT(isComplete() && !hasWork());

    for (auto& task : m_completionTasks)
        task.second->run(*this);
    m_completionTasks.clear();
    m_completed.notifyAll();
}
Example #2
0
void RunningProcs::run()
{
  I(cpuVector.size() > 0 );

  IS(currentCPU = 0);

  do{
    if ( workingList.empty() ) {
      EventScheduler::advanceClock();
    }

#ifdef TASKSCALAR
    HVersionDomain::tryPropagateSafeTokenAll();
#endif
    
    while (hasWork()) {
      stayInLoop=true;

      startProc = 0;

      do{
        // Loop duplicated so round-robin fetch starts on different
        // processor each cycle <><>

        for(size_t i=startProc ; i < workingList.size() ; i++) {
          if (workingList[i]->hasWork()) {
            currentCPU = workingList[i];
            currentCPU->advanceClock();
          }else{
            workingListRemove(workingList[i]);
          }
        }
        for(size_t i=0 ; i < startProc ; i++) {
          if (workingList[i]->hasWork()) {
            currentCPU = workingList[i];
            currentCPU->advanceClock();
          }else{
            workingListRemove(workingList[i]);
          }
        }

        startProc++;
        if (startProc >= workingList.size())
          startProc = 0;

        IS(currentCPU = 0);
        EventScheduler::advanceClock();
      }while(stayInLoop);
#ifdef SESC_THERM
      ReportTherm::stopCB();
#endif
    }
  }while(!EventScheduler::empty());
  
  
}
Example #3
0
    void doWork() override
    {
        if (!hasWork()) return;
        NodeID nodeID = currentNode();
        Node& node = _nodeTree->_nodes[nodeID];

        _tracer.setNode(nodeID);
        _reader.setNode(nodeID, node.numInputSockets());

        try
        {
            if(_withInit && node.flag(ENodeFlags::StateNode))
            {
                // Try to restart node internal state if any
                if(!node.restart())
                {
                    throw ExecutionError{node.nodeName(), nodeTypeName(nodeID),
                        "Error during node state restart"};
                }
            }

            ExecutionStatus ret = node.execute(_reader, _writer);

            switch (ret.status)
            {
            case EStatus::Tag:
                // Tag for next execution
                tagNode(nodeID);
                break;

            case EStatus::Error:
                // If node reported an error
                tagNode(nodeID);
                throw ExecutionError{node.nodeName(), nodeTypeName(nodeID), 
                    ret.message};
                break;

            case EStatus::Ok:
            default:
                break;
            }

            ++_pos;
        }
        catch (...)
        {
            _nodeTree->handleException(nodeID, _tracer);
        }
    }
Example #4
0
void indri::thread::UtilityThread::run() {
  indri::thread::ScopedLock lock( _lock );

  try {
    UINT64 waitTime = initialize();

    while( _runThread ) {
      bool noTimeout = _quit.wait( _lock, waitTime );

      if( noTimeout )
        continue; // interrupted

      waitTime = work();
    }

    while( hasWork() )
      work();

    deinitialize();
  } catch( lemur::api::Exception& e ) {
    std::cout << "UtilityThread exiting from exception " << e.what() << std::endl;
  }

}
void FileMonitorDelayQ::delayQLoop()
{
    VPLMutex_Lock(&m_delayQ_mutex);
    VPLTime_t currTime = VPLTime_GetTimeStamp();

    while (true) {

        ASSERT(!VPLMutex_LockedSelf(&m_api_mutex));
        // call callbacks
        while(hasWork(currTime)) {
            ASSERT(!m_delayQ.empty());

            FileMonitorDelayQCallback callback = NULL;
            void* context = NULL;
            FileMonitorHandleMap handleMap_out;

            DelayQEntry & entry = m_delayQ.front();
            if(GetHandleMap(m_delayQ.front().handle, handleMap_out)) {
                callback = handleMap_out.cb;
                context = handleMap_out.cb_ctx;
            } // else, callback will remain null and callback call skipped.
            VPLMutex_Unlock(&m_delayQ_mutex);

            if(callback) {
                callback(entry.handle,
                         entry.eventBuffer,
                         entry.eventBufferSize,
                         entry.error,
                         context);
            }

            VPLMutex_Lock(&m_delayQ_mutex);
            if(!m_delayQ.empty()) {
                cleanupDelayQEntry(m_delayQ.front());
                m_delayQ.pop_front();
            }
            if(!m_threadRunning) {
                goto exit;
            }
        }

        currTime = VPLTime_GetTimeStamp();
        // Wait for work to do.
        while (!hasWork(currTime))
        {
            VPLTime_t timeout = VPL_TIMEOUT_NONE;
            if(!m_delayQ.empty()) {
                VPLTime_t timeAlreadyWaited = VPLTime_DiffClamp(currTime, m_delayQ.front().timeQueued);
                timeout = VPLTime_DiffClamp(m_delayAmount, timeAlreadyWaited);
            }
            LOG_DEBUG("Sleeping for "FMTu64"ms", VPLTime_ToMillisec(timeout));
            int rc = VPLCond_TimedWait(&m_delayQ_cond_var, &m_delayQ_mutex, timeout);
            if ((rc != 0) && (rc != VPL_ERR_TIMEOUT)) {
                LOG_WARN("VPLCond_TimedWait failed: %d", rc);
            }
            if(!m_threadRunning) {
                goto exit;
            }
            currTime = VPLTime_GetTimeStamp();
        }
    } // while (1)
 exit:
    {
        // Could have exited with events still in the queue.
        for(std::deque<DelayQEntry>::iterator iter = m_delayQ.begin();
            iter != m_delayQ.end(); ++iter)
        {
            cleanupDelayQEntry(*iter);
        }
        m_delayQ.clear();
    }
    VPLMutex_Unlock(&m_delayQ_mutex);
}