Exemplo n.º 1
0
        void nfs_client_impl::continue_copy(int done_count)
        {
            if (done_count > 0)
            {
                _concurrent_copy_request_count -= done_count;
            }

            if (++_concurrent_copy_request_count > _opts.max_concurrent_remote_copy_requests)
            {
                --_concurrent_copy_request_count;
                return;
            }

            dsn::ref_ptr<copy_request_ex> req = nullptr;
            while (true)
            {
                {
                    zauto_lock l(_copy_requests_lock);
                    if (!_copy_requests.empty())
                    {
                        req = _copy_requests.front();
                        _copy_requests.pop();
                    }
                    else
                    {
                        --_concurrent_copy_request_count;
                        break;
                    }
                }

                {
                    zauto_lock l(req->lock);
                    if (req->is_valid)
                    {
                        req->add_ref();
                        req->remote_copy_task = copy(
                            req->copy_req,
                            [=](error_code err, copy_response&& resp)
                            {
                                end_copy(err, std::move(resp), req.get());
                            },
                            std::chrono::milliseconds(0),
                            0,
                            0,
                            0,
                            req->file_ctx->user_req->file_size_req.source);

                        if (++_concurrent_copy_request_count > _opts.max_concurrent_remote_copy_requests)
                        {
                            --_concurrent_copy_request_count;
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
std::tuple<double, double> get_spreading(It begin, It end) {
	// find the maximal distance between two points
	It end_copy(end);
	std::advance(end_copy, -1);
	double const max_ws = end_copy->x - begin->x;

	// find minimal distance between points
	double min_ws = max_ws;
	double x0 = begin->x;
	++begin;
	for (; begin != end; ++begin) {
		double const x1 = begin->x;
		double const ws = x1 - x0;
		if (ws < 0)
			throw std::invalid_argument("The container is unsorted");

		if (ws < min_ws)
			min_ws = ws;
		x0 = x1;
	}
	return std::make_tuple(min_ws, max_ws);
}