void RunningProcs::makeRunnable(ProcessId *proc) { // The process must be in the InvalidState I(proc->getState()==InvalidState); // Now the process is runnable (but still not running) ProcessId *victimProc=proc->becomeReady(); // Get the CPU where the process would like to run CPU_t cpu=proc->getCPU(); // If there is a preferred CPU, try to schedule there if(cpu>=0){ // Get the GProcessor of the CPU GProcessor *core=getProcessor(cpu); // Are there available flows on this CPU if(core->availableFlows()){ // There is an available flow, grab it switchIn(cpu,proc); return; } } // Could not run the process on the cpu it wanted // If the process is not pinned to that processor, try to find another cpu if(!proc->isPinned()){ // Find an available processor GProcessor *core=getAvailableProcessor(); // If available processor found, run there if(core){ switchIn(core->getId(),proc); return; } } // Could not run on an available processor // If there is a process to evict, switch it out and switch the new one in its place if(victimProc){ I(victimProc->getState()==RunningState); // get the processor where victim process is running cpu=victimProc->getCPU(); switchOut(cpu, victimProc); switchIn(cpu,proc); victimProc->becomeNonReady(); makeRunnable(victimProc); } // No free processor, no process to evict // The new process has to wait its turn }
void RunningProcs::makeNonRunnable(ProcessId *proc) { // It should still be running or ready I((proc->getState()==RunningState)||(proc->getState()==ReadyState)); // If it is still running, remove it from the processor if(proc->getState()==RunningState){ // Find the CPU where it is running CPU_t cpu=proc->getCPU(); // Remove it from there switchOut(cpu, proc); // Set the state to InvalidState to make the process non-runnable proc->becomeNonReady(); // Find another process to run on this cpu ProcessId *newProc=ProcessId::queueGet(cpu); // If a process has been found, switch it in if(newProc){ switchIn(cpu,newProc); } }else{ // Just set the state to InvalidState to make it non-runnable proc->becomeNonReady(); } }
void SmokeClassFiles::writeClass(QTextStream& out, const Class* klass, const QString& className, QSet<QString>& includes) { const QString underscoreName = QString(className).replace("::", "__"); const QString smokeClassName = "x_" + underscoreName; QString switchCode; QTextStream switchOut(&switchCode); out << QString("class %1").arg(smokeClassName); if (!klass->isNameSpace()) out << QString(" : public %1").arg(className); out << " {\n"; if (Util::canClassBeInstanciated(klass)) { out << " SmokeBinding* _binding;\n"; out << "public:\n"; out << " void x_0(Smoke::Stack x) {\n"; out << " // set the smoke binding\n"; out << " _binding = (SmokeBinding*)x[1].s_class;\n"; out << " }\n"; switchOut << " case 0: xself->x_0(args);\tbreak;\n"; } else { out << "public:\n"; } int xcall_index = 1; const Method *destructor = 0; foreach (const Method& meth, klass->methods()) { if (meth.access() == Access_private) continue; if (meth.isDestructor()) { destructor = &meth; continue; } switchOut << " case " << xcall_index << ": " << (((meth.flags() & Method::Static) || meth.isConstructor()) ? smokeClassName + "::" : "xself->") << "x_" << xcall_index << "(args);\tbreak;\n"; if (Util::fieldAccessors.contains(&meth)) { // accessor method? const Field* field = Util::fieldAccessors[&meth]; if (meth.name().startsWith("set")) { generateSetAccessor(out, className, *field, meth.parameters()[0].type(), xcall_index); } else { generateGetAccessor(out, className, *field, meth.type(), xcall_index); } } else { generateMethod(out, className, smokeClassName, meth, xcall_index, includes); } xcall_index++; } QString enumCode; QTextStream enumOut(&enumCode); const Enum* e = 0; bool enumFound = false; foreach (const BasicTypeDeclaration* decl, klass->children()) { if (!(e = dynamic_cast<const Enum*>(decl))) continue; if (e->access() == Access_private) continue; foreach (const EnumMember& member, e->members()) { switchOut << " case " << xcall_index << ": " << smokeClassName << "::x_" << xcall_index << "(args);\tbreak;\n"; if (e->parent()) generateEnumMemberCall(out, className, member.name(), xcall_index++); else generateEnumMemberCall(out, e->nameSpace(), member.name(), xcall_index++); } // only generate the xenum_call if the enum has a valid name if (e->name().isEmpty()) continue; enumFound = true; // xenum_operation method code QString enumString = e->toString(); enumOut << " case " << m_smokeData->typeIndex[&types[enumString]] << ": //" << enumString << '\n'; enumOut << " switch(xop) {\n"; enumOut << " case Smoke::EnumNew:\n"; enumOut << " xdata = (void*)new " << enumString << ";\n"; enumOut << " break;\n"; enumOut << " case Smoke::EnumDelete:\n"; enumOut << " delete (" << enumString << "*)xdata;\n"; enumOut << " break;\n"; enumOut << " case Smoke::EnumFromLong:\n"; enumOut << " *(" << enumString << "*)xdata = (" << enumString << ")xvalue;\n"; enumOut << " break;\n"; enumOut << " case Smoke::EnumToLong:\n"; enumOut << " xvalue = (long)*(" << enumString << "*)xdata;\n"; enumOut << " break;\n"; enumOut << " }\n"; enumOut << " break;\n"; } foreach (const Method* meth, Util::virtualMethodsForClass(klass)) { generateVirtualMethod(out, *meth, includes); }