void execute() { Futures inputFutures; for (const auto& namePort : _inputMap) { const Futures& futures = namePort.second.getFutures(); for (const auto& future : futures) inputFutures.emplace_back(future, namePort.second.getName()); } const FutureMap futures(inputFutures); PromiseMap promises(getOutputPromises()); try { _filter->execute(futures, promises); promises.flush(); } catch (const std::runtime_error& err) { promises.flush(); throw err; } catch (const std::logic_error& err) { promises.flush(); throw err; } }
Futures createthreads(bool& wait, int num) { Futures futures; for(int i = 0; i != num; ++i) futures.push_back(std::async(std::launch::async, [&wait]{ while(wait) std::this_thread::sleep_for(std::chrono::milliseconds(100)); })); return futures; }
Futures getPreconditions() const { Futures futures; for (const auto& namePort : _inputMap) { const Futures& inputFutures = namePort.second.getFutures(); futures.insert(futures.end(), inputFutures.begin(), inputFutures.end()); } return futures; }
Futures getPostconditions() const { Futures futures; for (const auto& namePort : _outputMap) { const Future& outputFuture = namePort.second.getPromise().getFuture(); futures.push_back(outputFuture); } return futures; }
void waitForAny( const Futures& futures ) { if( futures.empty( )) return; PortDataFutures boostFutures; boostFutures.reserve( futures.size( )); for( const auto& future: futures ) boostFutures.push_back( future._impl->_future ); boost::wait_for_any( boostFutures.begin(), boostFutures.end( )); }
Futures getFutures( const std::string& name ) const { if( name == ALL_FUTURES ) { Futures futures; for( const auto& nameFuture: _futureMap ) futures.push_back( nameFuture.second ); return futures; } if( !hasFuture( name )) throwError( name ); Futures futures; const auto& itPair = _futureMap.equal_range( name ); for( auto it = itPair.first; it != itPair.second; ++it ) futures.push_back( it->second ); return futures; }
void reduce_invoke(Action , Futures& futures , hpx::id_type const& id , std::size_t) { futures.push_back( hpx::async<Action>( id ) ); }
void reduce_invoke(reduce_with_index<Action> , Futures& futures , hpx::id_type const& id , std::size_t global_idx) { futures.push_back( hpx::async<Action>( id , global_idx ) ); }
int CTPUpdateFuturesPrice(Futures& fut, CThostFtdcDepthMarketDataField *md) { if (md==NULL) return 0; fut.ask1 = (md->AskPrice1>10000?-1:md->AskPrice1); fut.bid1 = (md->BidPrice1>10000?-1:md->BidPrice1); fut.ask1_vol = md->AskVolume1; fut.bid1_vol = md->BidVolume1; char Time[2]; fut.OpenPrice = md->OpenPrice; fut.LastPrice = ((md->LastPrice)>100000?-1:md->LastPrice); fut.PreSettlementPrice = md->PreSettlementPrice; std::cout<<md->SettlementPrice<<std::endl; fut.PreClosePrice = md->PreClosePrice; fut.HighPrice = md->HighestPrice; fut.LowPrice = md->LowestPrice; fut.AveragePrice = md->AveragePrice; fut.PreOpenInterest = md->PreOpenInterest; fut.Volume = md->Volume; fut.VolumeChange = fut.Volume-fut.PreVolume; fut.PreVolume = md->Volume; fut.OpenInterestChange = abs(md->OpenInterest - fut.OpenInterest); if (fut.OpenInterest == 0) fut.OpenInterestChange = 0; fut.OpenInterest = md->OpenInterest; fut.Turnover = md->Turnover; Time[0] = md->UpdateTime[0]; Time[1] = md->UpdateTime[1]; fut.hour = atoi(Time); Time[0] = md->UpdateTime[3]; Time[1] = md->UpdateTime[4]; fut.min = atoi(Time); Time[0] = md->UpdateTime[6]; Time[1] = md->UpdateTime[7]; fut.sec = atoi(Time); fut.milisec = md->UpdateMillisec; fut.updatePL(); return 0; };