MovementCommand &AllocateMovementCommand( void ) { //FIXME: calculate ~1s worth of input? if ( movementCmds.size() >= 10 ) { movementCmds.pop_front(); //FIXME: does this call destructor on pointer elements? } MovementCommand newCmd = {}; movementCmds.push_back( newCmd ); return movementCmds.back(); }
TSRTexture* TSRTextureManager::Aquire( const char* _pResourceName, eDefaultTextureType _typeHint, bool _bLoadImmediately ) { string Key = _pResourceName; if ( m_ResourcesMap.find( Key ) != m_ResourcesMap.end() ) { sResourceEntry& entry = m_ResourcesMap[ Key ]; entry.m_NumUsers++; return entry.m_pResource; } /// unlock this line to stream textures _bLoadImmediately = true; if ( _bLoadImmediately ) { // if not found..create a new entry sResourceEntry newEntry; newEntry.m_pResource = new TSRTexture( _pResourceName ); newEntry.m_NumUsers = 1; m_ResourcesMap[ Key ] = newEntry; return newEntry.m_pResource; } else { // if not found..create a new entry sResourceEntry newEntry; newEntry.m_pResource = new TSRTexture(); newEntry.m_NumUsers = 1; switch ( _typeHint ) { case DefaultTexture_Black: newEntry.m_pResource->m_pWrapped = m_pBlackTexture->m_pWrapped; break; case DefaultTexture_Normal: newEntry.m_pResource->m_pWrapped = m_pDefaultNormalTexture->m_pWrapped; break; default: newEntry.m_pResource->m_pWrapped = m_pWhiteTexture->m_pWrapped; break; } m_ResourcesMap[ Key ] = newEntry; /// add a new request to the queue sTextureLoadRequest newRequest; newRequest.m_pTextureToLoad = newEntry.m_pResource; newRequest.m_strFileName = _pResourceName; g_TextureLoadRequests.push_back( newRequest ); return newEntry.m_pResource; } }
bool TorControlConnection::Command(const std::string &cmd, const ReplyHandlerCB& reply_handler) { if (!b_conn) return false; struct evbuffer *buf = bufferevent_get_output(b_conn); if (!buf) return false; evbuffer_add(buf, cmd.data(), cmd.size()); evbuffer_add(buf, "\r\n", 2); reply_handlers.push_back(reply_handler); return true; }
void loadCaptureInfo(std::deque<Capture> &captures, const std::string &capturesFileName) { std::ifstream capturesFile(capturesFileName); if (capturesFile) { int actionType; sf::Int32 captureTime; while (capturesFile >> actionType >> captureTime) { captures.push_back(std::make_pair(actionType, captureTime)); } } else {
void enque(value_type const q) { { libmaus2::parallel::ScopePosixSpinLock llock(lock); Q.push_back(q); } semaphore.post(); if ( parent ) parent->enque(q); }
void gputask_Kick() { if(!g_gpuTasks.empty()) { auto ptr = g_gpuTasks.front(); g_gpuTasks.pop_front(); if(ptr->m_submit) ptr->m_submit(); if(ptr->m_complete) g_kickedTasks.push_back(ptr); } }
void setup() { while ( next < V.size() && freemem >= V[next]->directSortSpace() ) { freemem -= V[next]->directSortSpace(); pending.push_back(next); next += 1; } uint64_t const p = pending.size(); for ( uint64_t i = 0; i < p; ++i ) P.post(); }
void FrameStart() { ProcessFrames(); SFrame frame; frame.num = m_Profiler.GetFrameNumber(); frame.timeStart = m_Profiler.GetTime(); m_Frames.push_back(frame); RegionEnter("frame"); }
static void load_ia(std::deque<AObject*> &map, std::vector<int> &m_vector) { std::deque<AObject*>::iterator it; map.push_back(new Aintelligence(m_vector[POSX], m_vector[POSY], IA)); it = map.end(); --it; dynamic_cast<Player*>(*it)->setNbBomb((int)m_vector[BOMB_NB]); dynamic_cast<Player*>(*it)->setTotBomb((int)m_vector[BOMB_MAX]); dynamic_cast<Player*>(*it)->setSpeed((int)m_vector[SPEED]); dynamic_cast<Player*>(*it)->setRange((int)m_vector[RANGE]); }
void SDCFsiSolver::getVariablesInfo( std::deque<int> & dof, std::deque<bool> & enabled, std::deque<std::string> & names ) { std::deque<int> dofFluid, dofSolid; std::deque<bool> enabledFluid, enabledSolid; std::deque<std::string> namesFluid, namesSolid; fluid->getVariablesInfo( dofFluid, enabledFluid, namesFluid ); solid->getVariablesInfo( dofSolid, enabledSolid, namesSolid ); assert( dofFluid.size() == enabledFluid.size() ); assert( dofFluid.size() == namesFluid.size() ); assert( dofSolid.size() == enabledSolid.size() ); assert( dofSolid.size() == namesSolid.size() ); for ( unsigned int i = 0; i < dofFluid.size(); i++ ) { dof.push_back( dofFluid.at( i ) ); enabled.push_back( enabledFluid.at( i ) ); names.push_back( namesFluid.at( i ) ); } for ( unsigned int i = 0; i < dofSolid.size(); i++ ) { dof.push_back( dofSolid.at( i ) ); enabled.push_back( enabledSolid.at( i ) ); names.push_back( namesSolid.at( i ) ); } }
void LoadData(std::deque<mitk::ContourModelSet::Pointer> &r) { std::vector<itk::SmartPointer<mitk::BaseData> > readerOutput; readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/BODY.cnt_set")); mitk::ContourModelSet::Pointer cnt_set = dynamic_cast<mitk::ContourModelSet*>(readerOutput.at(0).GetPointer()); cnt_set->SetProperty("name", mitk::StringProperty::New("BODY")); r.push_back(cnt_set); readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/Bladder.cnt_set")); cnt_set = dynamic_cast<mitk::ContourModelSet*>(readerOutput.at(0).GetPointer()); cnt_set->SetProperty("name", mitk::StringProperty::New("Bladder")); r.push_back(cnt_set); readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/Femoral Head Lt.cnt_set")); cnt_set = dynamic_cast<mitk::ContourModelSet*>(readerOutput.at(0).GetPointer()); cnt_set->SetProperty("name", mitk::StringProperty::New("Femoral Head Lt")); r.push_back(cnt_set); readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/Femoral Head RT.cnt_set")); cnt_set = dynamic_cast<mitk::ContourModelSet*>(readerOutput.at(0).GetPointer()); cnt_set->SetProperty("name", mitk::StringProperty::New("Femoral Head RT")); r.push_back(cnt_set); readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/PTV.cnt_set")); cnt_set = dynamic_cast<mitk::ContourModelSet*>(readerOutput.at(0).GetPointer()); cnt_set->SetProperty("name", mitk::StringProperty::New("PTV")); r.push_back(cnt_set); readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/Rectum.cnt_set")); cnt_set = dynamic_cast<mitk::ContourModelSet*>(readerOutput.at(0).GetPointer()); cnt_set->SetProperty("name", mitk::StringProperty::New("Rectum")); r.push_back(cnt_set); }
void run_sim(void) { BondMap::iterator weakest; Bond hypocenter; counter = 0; for (i=0; i<N;) { weakest = accessibleBonds.begin(); already_invaded = invade_bond(weakest->second, weakest->first); if(!already_invaded) { if(weakest->first < cutoff) { if(counter == 0) { hypocenter = weakest->second; } counter +=1; } else { if(counter != 0) { if(burst_counts.count(counter) > 0) { burst_counts[counter] += 1; } else { burst_counts.insert(std::make_pair(counter,1)); } burst_list.push_back(boost::make_tuple(hypocenter.first.first, hypocenter.first.second, counter)); counter = 0; } } if(chem_level_list.count(weakest->second.first ) > 0) { chem_level_list.insert(std::make_pair(weakest->second.second, chem_level_list[weakest->second.first]+1)); } else { chem_level_list.insert(std::make_pair(weakest->second.second, 1)); } i++; } accessibleBonds.erase(weakest); } }
void AdminClient::internal_write(message msg) { bool writing = !write_queue_.empty(); //std::cout << "Adding message \"" << msg.data() << "\" to queue\n"; write_queue_.push_back(msg); if (!writing){ boost::asio::async_write(sock_, boost::asio::buffer(write_queue_.front().data()), boost::bind(&AdminClient::write_handler, this, boost::asio::placeholders::error)); } }
void push(const TaskPtr& task) { if (!_running) { return; } boost::unique_lock<boost::mutex> lock(_mutex); std::cout << "push A" << std::endl; _tasks.push_back(task); if (_tasks.size() >= 1) { std::cout << "push B" << std::endl; _no_task.notify_one(); std::cout << "push C" << std::endl; } }
void recurDir(const std::string &pathName, std::deque<std::string> &queue) { DIR *dir = opendir(pathName.c_str()); if (!dir) { std::cerr << pathName << ": " << strerror(errno) << std::endl; return; } while (dirent *aFile = readdir(dir)) { if (aFile->d_name[0] == '.') continue; std::string path = pathName + "/" + aFile->d_name; queue.push_back(path); } closedir(dir); }
void genSprites3d(float size,int across, int depth, std::deque<sparky::graphics::Renderable3D*>& queue, sparky::graphics::Window& window){ sparky::maths::vec3 s(size * 0.9f,0.01f, size * 0.9f); for (float y = size * 0.05; y < 50; y += size){ for (float x = size * 0.05; x < 10; x += size){ queue.push_back(new sparky::graphics::Renderable3D (sparky::maths::vec3(x - (WINDOW_WIDTH/2), -0.5, y-1), s, sparky::maths::vec4(rand() % 1000 / 1000.0f, rand() % 1000 / 1000.0f, rand() % 1000 / 1000.0f, 1) )); } } }
void visualizerShowCamera(const Matrix3f& R, const Vector3f& _t, float r, float g, float b, double s = 0.01 /*downscale factor*/, const std::string& name = "") { std::string name_ = name,line_name = name + "line"; if (name.length() <= 0) { stringstream ss; ss<<"camera"<<iCamCounter++; name_ = ss.str(); ss << "line"; line_name = ss.str(); } Vector3f t = -R.transpose() * _t; Vector3f vright = R.row(0).normalized() * s; Vector3f vup = -R.row(1).normalized() * s; Vector3f vforward = R.row(2).normalized() * s; Vector3f rgb(r,g,b); pcl::PointCloud<pcl::PointXYZRGB> mesh_cld; mesh_cld.push_back(Eigen2PointXYZRGB(t,rgb)); mesh_cld.push_back(Eigen2PointXYZRGB(t + vforward + vright/2.0 + vup/2.0,rgb)); mesh_cld.push_back(Eigen2PointXYZRGB(t + vforward + vright/2.0 - vup/2.0,rgb)); mesh_cld.push_back(Eigen2PointXYZRGB(t + vforward - vright/2.0 + vup/2.0,rgb)); mesh_cld.push_back(Eigen2PointXYZRGB(t + vforward - vright/2.0 - vup/2.0,rgb)); //TODO Mutex acquire pcl::PolygonMesh pm; pm.polygons.resize(6); for(int i=0;i<6;i++) for(int _v=0;_v<3;_v++) pm.polygons[i].vertices.push_back(ipolygon[i*3 + _v]); pcl::toROSMsg(mesh_cld,pm.cloud); bShowCam = true; cam_meshes.push_back(std::make_pair(name_,pm)); //TODO mutex release linesToShow.push_back(std::make_pair(line_name, AsVector(Eigen2Eigen(t,rgb),Eigen2Eigen(t + vforward*3.0,rgb)) )); }
std::future<void> async(_Function&& work, _Args&&... args) { auto promise_ptr = std::make_shared<std::promise<void>>(); do { if (std::this_thread::get_id() != thread_.get_id()) { std::lock_guard<std::recursive_mutex> api_lock(api_mutex_); if (!is_running_) { throw std::runtime_error("Not running"); } std::lock_guard<std::mutex> lock(works_mutex_); works_.push_back([=]() { try { work(args...); promise_ptr->set_value(); } catch (...) { promise_ptr->set_exception(std::current_exception()); } }); workable_.notify_all(); } else { if (!is_running_) { throw std::runtime_error("Not running"); } std::lock_guard<std::mutex> lock(works_mutex_); works_.push_back([=]() { try { work(args...); promise_ptr->set_value(); } catch (...) { promise_ptr->set_exception(std::current_exception()); } }); workable_.notify_all(); } } while (0); return promise_ptr->get_future(); }
/** ** Send chat message. (Message is sent with low priority) ** ** @param msg Text message to send. */ void NetworkSendChatMessage(const std::string &msg) { if (!IsNetworkGame()) { return; } CNetworkChat nc; nc.Text = msg; CNetworkCommandQueue ncq; ncq.Type = MessageChat; ncq.Data.resize(nc.Size()); nc.Serialize(&ncq.Data[0]); MsgCommandsIn.push_back(ncq); }
void AppendData(double mass) { wxLongLong_t now = ::wxGetUTCTimeMillis().GetValue(); wxLongLong_t oldest = now - m_timeWindow; while (m_data.size() > 0 && m_data.front().time < oldest) m_data.pop_front(); Entry entry; entry.time = now; entry.mass = mass; m_data.push_back(entry); }
int write(char *bf,long long len) { pthread_mutex_lock(&mutex); int writeCnt = 0; while(len > 0) { data.push_back(*bf++); len--; writeCnt++; } pthread_mutex_unlock(&mutex); return writeCnt; }
value_type* push_anywhere(T& dat) { if (!freelist.empty()) { value_type* ret = freelist.front(); ret->first = dat; ret->second = false; freelist.pop_front(); return ret; } else { data.push_back(std::make_pair(dat, false)); return &(data.back()); } }
void put(T &&x, std::chrono::milliseconds time_out = INFINITE) { { auto_lock lock(mutex_); while(queue_.size() == max_size_ ) not_full_.wait_for(mutex_, time_out); assert(queue_.size() != max_size_); queue_.push_back(std::forward<T>(x)); } not_empty_.notify_one(); }
bool Handle( std::shared_ptr<BlurryRoots::Yanecos::IEvent> someEvent ) { if( someEvent->GetType() == typeid( ActorMoveRequestEvent ) ) { auto event = std::static_pointer_cast<ActorMoveRequestEvent>( someEvent ); _moveRequests.push_back( event ); } }
bool RegionWellsReader::loadRegion(std::deque<int> &wellX, std::deque<int> &wellY, std::deque<std::vector<float> > &wellMeasurements, int regionX, int regionY, Mask *mask) { if ((regionX >= numRegionsX) || (regionY >= numRegionsY)) return false; wellX.clear(); wellY.clear(); wellMeasurements.clear(); pthread_mutex_lock(read_mutex); int Y = std::min(regionY*sizeRegionY,(int)wells->NumRows()); int X = std::min(regionX*sizeRegionX,(int)wells->NumCols()); int nY = ((regionY+1)*sizeRegionY); int nX = ((regionX+1)*sizeRegionX); wells->SetChunk(Y, std::min(nY-Y,(int)wells->NumRows() - Y), X, std::min(nX-X,(int)wells->NumCols() - X), 0, wells->NumFlows()); wells->ReadWells(); for (int nextY = regionY * sizeRegionY; (nextY < (regionY + 1) * sizeRegionY) && (nextY < sizeY); nextY++) { for (int nextX = regionX * sizeRegionX; (nextX < (regionX + 1) * sizeRegionX) && (nextX < sizeX); nextX++) { if (!mask->Match(nextX, nextY, MaskTF) && !mask->Match(nextX, nextY, MaskLib)) continue; wellX.push_back(nextX); wellY.push_back(nextY); wellMeasurements.push_back(std::vector<float>()); wellMeasurements.back().resize(numFlows); const WellData *w = wells->ReadXY(nextX, nextY); copy(w->flowValues, w->flowValues + numFlows, wellMeasurements.back().begin()); } } pthread_mutex_unlock(read_mutex); return true; // Region reading successful }
std::shared_ptr<WalletRequest> WalletTransactionSender::doSendTransaction(std::shared_ptr<SendTransactionContext> context, std::deque<std::shared_ptr<WalletEvent> >& events) { if (m_isStoping) { events.push_back(std::make_shared<WalletSendTransactionCompletedEvent>(context->transactionId, make_error_code(cryptonote::error::TX_CANCELLED))); return std::shared_ptr<WalletRequest>(); } try { Transaction& transaction = m_transactionsCache.getTransaction(context->transactionId); std::vector<cryptonote::tx_source_entry> sources; prepareInputs(context->selectedTransfers, context->outs, sources, context->mixIn); cryptonote::tx_destination_entry changeDts = AUTO_VAL_INIT(changeDts); createChangeDestinations(m_keys.m_account_address, transaction.totalAmount, context->foundMoney, changeDts); std::vector<cryptonote::tx_destination_entry> splittedDests; splitDestinations(transaction.firstTransferId, transaction.transferCount, changeDts, context->dustPolicy, splittedDests); cryptonote::transaction tx; constructTx(m_keys, sources, splittedDests, transaction.extra, context->unlockTimestamp, m_upperTransactionSizeLimit, tx); fillTransactionHash(tx, transaction.hash); m_unconfirmedTransactions.add(tx, context->transactionId, changeDts.amount); notifyBalanceChanged(events); return std::make_shared<WalletRelayTransactionRequest>(tx, std::bind(&WalletTransactionSender::relayTransactionCallback, this, context->transactionId, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); } catch(std::system_error& ec) { events.push_back(std::make_shared<WalletSendTransactionCompletedEvent>(context->transactionId, ec.code())); } catch(std::exception&) { events.push_back(std::make_shared<WalletSendTransactionCompletedEvent>(context->transactionId, make_error_code(cryptonote::error::INTERNAL_WALLET_ERROR))); } return std::shared_ptr<WalletRequest>(); }
// process a match // node, a matched node // command, next command to process void match_found(variant* node, std::vector<vtpath_command>::iterator inext_command) { if( inext_command == commands.end() ) { TINFRA_TRACE(vtpath_exec_tracer, "vpath_visit: matched result: " << node << ": " << *node); // if we're at end of pattern, i.e no rules // that means that we've been matched "directly" // so mark CURRENT as a result result_queue.push_back(node); return; } else { push_container(node, inext_command); } }
void processCmdLine(int32_t aCount, char ** anArgList) { if (aCount < 4) { usage(); std::exit(-1); } int64_t start_insn = boost::lexical_cast<int64_t>( anArgList[1] ); int64_t end_insn = boost::lexical_cast<int64_t>( anArgList[2] ); if (start_insn >= end_insn) { std::cout << "Start instruction must exceed end instruction\n"; std::exit(-1); } std::string input_file = anArgList[3]; std::string output_file = anArgList[4]; theCommands.push_back( ll::bind( &loadDatabase, input_file ) ); theCommands.push_back( ll::bind( &computeRegions, start_insn, end_insn ) ); theCommands.push_back( ll::bind( &reduceSum, ll::var(region_string) ) ); theCommands.push_back( ll::bind( &save, output_file, "selection" ) ); }
void WalletTransactionSender::sendTransactionRandomOutsByAmount(std::shared_ptr<SendTransactionContext> context, std::deque<std::shared_ptr<WalletEvent> >& events, boost::optional<std::shared_ptr<WalletRequest> >& nextRequest, std::error_code ec) { if (m_isStoping) { events.push_back(std::make_shared<WalletSendTransactionCompletedEvent>(context->transactionId, make_error_code(cryptonote::error::TX_CANCELLED))); return; } if (ec) { events.push_back(std::make_shared<WalletSendTransactionCompletedEvent>(context->transactionId, ec)); return; } auto scanty_it = std::find_if(context->outs.begin(), context->outs.end(), [&] (cryptonote::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& out) {return out.outs.size() < context->mixIn;}); if (scanty_it != context->outs.end()) { events.push_back(std::make_shared<WalletSendTransactionCompletedEvent>(context->transactionId, make_error_code(cryptonote::error::MIXIN_COUNT_TOO_BIG))); return; } std::shared_ptr<WalletRequest> req = doSendTransaction(context, events); if (req) nextRequest = req; }
void NewObjInGlobal() { int percent = RandomRange(1, 100); if (percent <= 20) { g_globalTable.push_back(g_gc.NewTable(luna::GCGen2)); } else if (percent <= 50) { g_globalString.push_back(g_gc.NewString(luna::GCGen2)); } else if (percent <= 60) { if (!g_globalFunction.empty()) { auto index = RandomNum(g_globalFunction.size()); auto proto = g_globalFunction[index]; auto c = g_gc.NewClosure(luna::GCGen1); c->SetPrototype(proto); g_globalClosure.push_back(c); } } }