void C4Network2UPnPP::ClearMappings()
{
	action = std::async([this, action = std::move(action)]() {
		action.wait();

		for (auto mapping : added_mappings)
			RemovePortMapping(mapping);

		added_mappings.clear();
	});
}
void handleFuture( std::future< _2Real::BlockResult > &obj, std::string const& info = "" )
{
	obj.wait();
	_2Real::BlockResult val = obj.get();
	switch ( val )
	{
	case _2Real::BlockResult::CARRIED_OUT:
		std::cout << "---- " << info << " was carried out" << std::endl;
		break;
	case _2Real::BlockResult::IGNORED:
		std::cout << "---- " << info << " was ignored" << std::endl;
		break;
	}
}
void C4Network2UPnPP::AddMapping(C4Network2IOProtocol protocol, uint16_t intport, uint16_t extport)
{
	PortMapping mapping;
	mapping.external_port = extport;
	mapping.internal_port = intport;
	mapping.protocol = (protocol == P_TCP ? "TCP" : "UDP");

	added_mappings.push_back(mapping);

	action = std::async([this, action = std::move(action), mapping]() {
		action.wait();
		AddPortMapping(mapping);
	});
}
Beispiel #4
0
void AI::WaitForFuture(const std::future<void>& fut, bool bPondering)
{
	std::uint64_t timePerMove = GetTimePerMove();
	if(bPondering)
	{
		timePerMove /= 2;
	}

	// Wait until the thread finishes or it gets timed out
	if(fut.wait_for(std::chrono::nanoseconds(timePerMove)) == std::future_status::timeout)
	{
		// If the thread did not finish execution, signal the thread to exit, and wait till the thread exits.
	
		m_bStopMinimax = true;
		fut.wait();
		m_bStopMinimax = false;
	}
}
 void schedule(std::weak_ptr<Mailbox>) final {
     promise.set_value();
     future.wait();
     std::this_thread::sleep_for(1ms);
     waited = true;
 }
 void wait() {
     promise.set_value();
     future.wait();
     std::this_thread::sleep_for(1ms);
     waited = true;
 }
 ~ConcurrentAccess() {
     queue_.Push([=]{done_ = true;});
     f_.wait();
 }