bool System::banker(Process *process) { bool rtn; unsigned int available_bk = getAvailable(); unsigned int num = process->getRequestNeed(); processUid.clear(); for(auto i = processList.begin(); i != processList.end(); ) { if(false == (*i)->isFinish() && (*i)->getMaxNeed() - (*i)->getOwnNeed() <= getAvailable()) { (*i)->setFinish(true); setAvailable(getAvailable()+(*i)->getOwnNeed()); processUid.push_back((*i)->getUid()); i = processList.begin(); } else { ++i; } } rtn = true; for(auto i = processList.begin(); i != processList.end(); ++i) { if((*i)->isFinish() == false) rtn = false; (*i)->setFinish(false); } setAvailable(available_bk); return rtn; }
unsigned int System::attainResource(Process *process) { wait(); int rtn = 0; unsigned int requestNum = process->getRequestNeed(); unsigned int available_bk = getAvailable(); unsigned int ownNeed_bk = process->getOwnNeed(); std::string prompt; if(requestNum <= getAvailable()) { setAvailable(getAvailable() - requestNum); process->setOwnNeed(process->getOwnNeed() + requestNum); prompt = prompt + "\nsystem" + "\t" + std::to_string(available_bk) + '\n'; std::cout << prompt; prompt.clear(); if(banker(process)) { processList.insert(process); prompt = prompt + "Thread" + "\t" + std::to_string(process->getUid()) + "\t" + std::to_string(process->getMaxNeed()) + "\t" + std::to_string(process->getOwnNeed()) + "\t" + std::to_string(process->getRequestNeed()) + "\t" + "Success\n"; std::cout << prompt; rtn = 0; } else { setAvailable(available_bk); process->setOwnNeed(ownNeed_bk); prompt = prompt + "Thread" + "\t" + std::to_string(process->getUid()) + "\t" + std::to_string(process->getMaxNeed()) + "\t" + std::to_string(process->getOwnNeed()) + "\t" + std::to_string(process->getRequestNeed()) + "\t" + "Failure\n"; std::cout << prompt; rtn = 1; } printProcessList(std::cout); } else { rtn = 1; } release(); return rtn; }
void LLThrottle::setRate(const F32 rate) { // Need to accumulate available bits when adjusting the rate. mAvailable = getAvailable(); mLastSendTime = LLMessageSystem::getMessageTimeSeconds(); mRate = rate; }
void Search_Branch_And_Bound_Improved_Threaded<RETURNTYPE,DIMTYPE,SUBSET,CRITERION,max_threads>::pre_evaluate_availables() { assert(currentset); assert(grandparent::get_criterion()); const PSubset ¤tset=grandparent::get_currentset(); // pre-evaluate available features before next tree level construction RETURNTYPE value; DIMTYPE feature; typename grandparent::PNode avail; for(bool got=getFirstAvailable(avail);got;got=getNextAvailable(avail)) { assert(currentset->selected_raw(avail->feature)); currentset->deselect_raw(avail->feature); _evaluator.add_candidate(currentset,avail->feature); currentset->select_raw(avail->feature); } PSubset dummysub; for(bool got=_evaluator.getFirstResult(value,dummysub,feature);got;got=_evaluator.getNextResult(value,dummysub,feature)) { if(getAvailable(feature,avail)) { avail->value=value; avail->type=grandparent::COMPUTED; } } }
size_type StreamChild::read(void* pData, size_type nSize) { if(mnAccessFlags) // If open... { // We have a potential problem here with respect to multi-threaded // access to the parent. With multi-threaded usage of mpStreamParent // it's possible that a second thread could alter the position of // the parent stream between the SetPosition and read calls below. if(mpStreamParent->setPosition((off_type)(mnPositionParent + mnPosition))) { size_type nAvailable(getAvailable()); if (nAvailable < nSize) // allow read to end of our range { nSize = nAvailable; } if(mpStreamParent->read(pData, nSize) == nSize) { mnPosition += nSize; return nSize; } } } return kSizeTypeError; }
STDMETHODIMP VBoxSVCAvailabilityChangedEventWrap::COMGETTER(Available)(BOOL *aAvailable) { LogRelFlow(("{%p} %s: enter aAvailable=%p\n", this, "VBoxSVCAvailabilityChangedEvent::getAvailable", aAvailable)); VirtualBoxBase::clearError(); HRESULT hrc; try { CheckComArgOutPointerValidThrow(aAvailable); AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) throw autoCaller.rc(); hrc = getAvailable(aAvailable); } catch (HRESULT hrc2) { hrc = hrc2; } catch (...) { hrc = VirtualBoxBase::handleUnexpectedExceptions(this, RT_SRC_POS); } LogRelFlow(("{%p} %s: leave *aAvailable=%RTbool hrc=%Rhrc\n", this, "VBoxSVCAvailabilityChangedEvent::getAvailable", *aAvailable, hrc)); return hrc; }
bool System::freeResource(Process *process) { wait(); bool rtn; if(processList.find(process) == processList.end()) rtn = false; else rtn = true; setAvailable(getAvailable() + process->getOwnNeed()); processList.erase(process); release(); return rtn; }
bool GTB::load() { if (path.size() == 0)return false; memset(installedPieces, 0, sizeof(installedPieces)); if (!FileUtil::fileExists(path)) { cout << "file not found " << path << endl; return false; } tbstats_reset(); paths = tbpaths_done(paths); paths = tbpaths_init(); _assert(paths); paths = tbpaths_add(paths, path.c_str()); restart(); unsigned av = tb_availability(); if (0 != (av & 2)) { setInstalledPieces(3); cout << "3-pc TBs complete\n"; } else if (0 != (av & 1)) { cout << "Some 3-pc TBs available\n"; } else { cout << "No 3-pc TBs available\n"; } if (0 != (av & 8)) { setInstalledPieces(4); cout << "4-pc TBs complete\n"; } else if (0 != (av & 4)) { cout << "Some 4-pc TBs available\n"; } else { cout << "No 4-pc TBs available\n"; } if (0 != (av & 32)) { setInstalledPieces(5); cout << "5-pc TBs complete\n"; } else if (0 != (av & 16)) { cout << "Some 5-pc TBs available\n"; } else { cout << "No 5-pc TBs available\n"; } cout << endl; if (!getAvailable()) { return false; } setCacheSize(cacheSize); tb_init(verbosity, scheme, paths); tbcache_init(cacheSize * 1024 * 1024, wdl_fraction); tbstats_reset(); return true; }
bool LaTeXFeatures::isAvailable(string const & name) { string::size_type const i = name.find("->"); if (i != string::npos) { string const from = name.substr(0,i); string const to = name.substr(i+2); //LYXERR0("from=[" << from << "] to=[" << to << "]"); return theConverters().isReachable(from, to); } if (packages_.empty()) getAvailable(); string n = name; if (suffixIs(n, ".sty")) n.erase(name.length() - 4); return packages_.find(n) != packages_.end(); }
/* Return the number of byes available to be read without blocking */ JNIEXPORT jint JNICALL Java_org_apache_harmony_luni_internal_process_ProcessInputStream_availableImpl (JNIEnv * env, jobject recv) { jlong sHandle; int retVal; sHandle = (*env)->GetLongField (env, recv, HARMONY_CACHE_GET (env, FID_org_apache_harmony_luni_internal_process_ProcessInputStream_handle)); retVal = getAvailable ((jint)sHandle); if (retVal < 0) { /* Couldn't read bytes */ throwJavaIoIOException(env, "Unable to peek on stream"); } return (jint) retVal; }
DECLARE_EXPORT PyObject* Location::getattro(const Attribute& attr) { if (attr.isA(Tags::tag_name)) return PythonObject(getName()); if (attr.isA(Tags::tag_description)) return PythonObject(getDescription()); if (attr.isA(Tags::tag_category)) return PythonObject(getCategory()); if (attr.isA(Tags::tag_subcategory)) return PythonObject(getSubCategory()); if (attr.isA(Tags::tag_owner)) return PythonObject(getOwner()); if (attr.isA(Tags::tag_available)) return PythonObject(getAvailable()); if (attr.isA(Tags::tag_hidden)) return PythonObject(getHidden()); if (attr.isA(Tags::tag_members)) return new LocationIterator(this); return NULL; }