/** * @brief Construct a fence object in unsignaled state */ shared_fence(const vk::vk_logical_device<> &device, const char *name) : f(device, name, false), future(promise.get_future().share()) {}
std::future<int> doit() { BARK(); auto cb = [&](const boost::system::error_code&) { std::cout << "CB!\n"; prom.set_value(13); }; dt.async_wait(cb); return prom.get_future(); }
Impl(GeneratorHandler &handler, const QString &fileName) : m_handler(handler) , m_outp(fileName.toStdString()) , m_thread(&Impl::ThreadFunction, this) { if (!m_outp.is_open()) throw std::invalid_argument("Cannot write to " + fileName.toStdString()); auto threadStartWaiter = m_promice.get_future(); threadStartWaiter.get(); }
shared_fence(const vk::vk_logical_device<> &device, T &&val, const char *name, typename std::enable_if<!std::is_void<S>::value>::type* = nullptr) : f(device, name, true), future(promise.get_future().share()) { promise.set_value(std::forward<T>(val)); }
FM<T>& set(SM<T, Ts...>& input, const bool is_lazy, Ts&... args) { _promise = std::promise<T>(); _future = _promise.get_future(); auto f = std::async( is_lazy ? std::launch::deferred : std::launch::async, [&] () { task_loop<T, Ts...>()(input, _promise, args...); } ); if(is_lazy) f.get(); return *this; };
shared_fence(const vk::vk_logical_device<> &device, bool signaled, const char *name, typename std::enable_if<std::is_void<S>::value>::type* = nullptr) : f(device, name, signaled), future(promise.get_future().share()) { if (signaled) promise.set_value(); }
interfaceHandlerDBusConnection->unregisterObjectPath(objectPath); ASSERT_TRUE(interfaceHandlerDBusConnection->releaseServiceName(busName)); interfaceHandlerDBusConnection->disconnect(); } void dispatch(::DBusConnection* libdbusConnection) { dbus_bool_t success = TRUE; while (success) { success = dbus_connection_read_write_dispatch(libdbusConnection, 1); } } std::promise<bool> promise; std::future<bool> future = promise.get_future(); void notifyThunk(DBusPendingCall*, void* data) { ::DBusConnection* libdbusConnection = reinterpret_cast<DBusConnection*>(data); dbus_connection_close(libdbusConnection); dbus_connection_unref(libdbusConnection); promise.set_value(true); } TEST_F(DBusConnectionTest, LibdbusConnectionsMayCommitSuicide) { const ::DBusBusType libdbusType = ::DBusBusType::DBUS_BUS_SESSION; ::DBusError libdbusError; dbus_error_init(&libdbusError); ::DBusConnection* libdbusConnection = dbus_bus_get_private(libdbusType, &libdbusError); assert(libdbusConnection);
/** * @brief Resets fence to unsignaled state * Not thread-safe. */ void reset() override { f.reset(); promise = std::promise<R>(); future = promise.get_future().share(); }
std::future<T> getFuture() { return result->get_future(); }
void join() { std::future<void> future = stop_promise.get_future(); future.get(); }
int main(int argc, char *argv[]) { auto log = logger::log("MAIN"); log->info("start"); // Check if validators are registered. if (not config_validator_registered or not keypair_name_validator_registered) { // Abort execution if not log->error("Flag validator is not registered"); return EXIT_FAILURE; } namespace mbr = config_members; // Parsing command line arguments gflags::ParseCommandLineFlags(&argc, &argv, true); gflags::ShutDownCommandLineFlags(); // Reading iroha configuration file auto config = parse_iroha_config(FLAGS_config); log->info("config initialized"); // Reading public and private key files iroha::KeysManagerImpl keysManager(FLAGS_keypair_name); auto keypair = keysManager.loadKeys(); // Check if both keys are read properly if (not keypair) { // Abort execution if not log->error("Failed to load keypair"); return EXIT_FAILURE; } // Configuring iroha daemon Irohad irohad(config[mbr::BlockStorePath].GetString(), config[mbr::PgOpt].GetString(), config[mbr::ToriiPort].GetUint(), config[mbr::InternalPort].GetUint(), config[mbr::MaxProposalSize].GetUint(), std::chrono::milliseconds(config[mbr::ProposalDelay].GetUint()), std::chrono::milliseconds(config[mbr::VoteDelay].GetUint()), std::chrono::milliseconds(config[mbr::LoadDelay].GetUint()), *keypair, config[mbr::MstSupport].GetBool()); // Check if iroha daemon storage was successfully initialized if (not irohad.storage) { // Abort execution if not log->error("Failed to initialize storage"); return EXIT_FAILURE; } // Check if genesis block path was specified if (not FLAGS_genesis_block.empty()) { // If it is so, read genesis block and store it to iroha storage iroha::main::BlockLoader loader; auto file = loader.loadFile(FLAGS_genesis_block); auto block = loader.parseBlock(file.value()); // Check that provided genesis block file was correct if (not block) { // Abort execution if not log->error("Failed to parse genesis block"); return EXIT_FAILURE; } // check if ledger data already existing auto ledger_not_empty = irohad.storage->getBlockQuery()->getTopBlockHeight() != 0; // Check if force flag to overwrite ledger is specified if (ledger_not_empty && not FLAGS_overwrite_ledger) { log->error( "Block store not empty. Use '--overwrite_ledger' to force " "overwrite it. Shutting down..."); return EXIT_FAILURE; } // clear previous storage if any irohad.dropStorage(); // reset ordering service persistent counter irohad.resetOrderingService(); log->info("Block is parsed"); // Applying transactions from genesis block to iroha storage irohad.storage->insertBlock(*block.value()); log->info("Genesis block inserted, number of transactions: {}", block.value()->transactions().size()); } // check if at least one block is available in the ledger auto blocks_exist = irohad.storage->getBlockQuery()->getTopBlock().match( [](const auto &) { return true; }, [](iroha::expected::Error<std::string> &) { return false; }); if (not blocks_exist) { log->error( "There are no blocks in the ledger. Use --genesis_block parameter."); return EXIT_FAILURE; } // init pipeline components irohad.init(); auto handler = [](int s) { exit_requested.set_value(); }; std::signal(SIGINT, handler); std::signal(SIGTERM, handler); std::signal(SIGQUIT, handler); // runs iroha log->info("Running iroha"); irohad.run(); exit_requested.get_future().wait(); // We do not care about shutting down grpc servers // They do all necessary work in their destructors log->info("shutting down..."); return 0; }