当前位置: 首页>>代码示例>>C++>>正文


C++ ProcessId::setCPU方法代码示例

本文整理汇总了C++中ProcessId::setCPU方法的典型用法代码示例。如果您正苦于以下问题:C++ ProcessId::setCPU方法的具体用法?C++ ProcessId::setCPU怎么用?C++ ProcessId::setCPU使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProcessId的用法示例。


在下文中一共展示了ProcessId::setCPU方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: contextSwitch

Pid_t OSSim::contextSwitch(CPU_t cpu, Pid_t nPid)
{
    // This is the process we displaced to run the target process
    Pid_t oldPid=-1;
    ProcessId *newProc = ProcessId::getProcessId(nPid);
    I(newProc);
    GProcessor *newCore=cpus.getProcessor(cpu);
    I(newCore);
    // Get the cpu where the target process is already running
    CPU_t runCpu=(newProc->getState()==RunningState)?newProc->getCPU():-1;
    // If already running on the target processor, do nothing
    if(runCpu==cpu)
        return -1;
    // If target core has no available flows, make one
    if(!newCore->availableFlows()) {
        oldPid=newCore->findVictimPid();
        ProcessId *oldProc=ProcessId::getProcessId(oldPid);
        cpus.switchOut(cpu, oldProc);
    }
    // Is the target process already running on another cpu?
    if(runCpu!=-1) {
        // Get another process to run on original cpu
        ProcessId *repProc=ProcessId::queueGet(runCpu);
        // Get the target process out of old core
        cpus.switchOut(runCpu, newProc);
        // Get the replacement process (if any) into the old core
        if(repProc)
            cpus.switchIn(runCpu,repProc);
        // Get the target process in the target cpu
        cpus.switchIn(cpu, newProc);
    } else {
        // If new process not ready, make it ready
        if(newProc->getState()!=ReadyState) {
            // Make it prefer the target cpu
            newProc->setCPU(cpu);
            // Make it ready
            newProc->setState(InvalidState);
            cpus.makeRunnable(newProc);
            // The target cpu is prefered by the target process, and
            // the target cpu has available flows. Thus, the target
            // process should be now running on the target cpu
            I(newProc->getCPU()==cpu);
            I(newProc->getState()==RunningState);
        } else {
            // The new process is already ready, just switch it in
            cpus.switchIn(cpu,newProc);
        }
    }
    return oldPid;
}
开发者ID:Walkerks,项目名称:SESCLease-Release,代码行数:50,代码来源:OSSim.cpp


注:本文中的ProcessId::setCPU方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。