mirror of
https://github.com/EttusResearch/uhd.git
synced 2026-10-25 17:36:10 +00:00
rpc: Use perfect forwarding in rpc code
Some instances of RPC code had rvalue reference arguments but did not use std::forward wenn passing these arguments (or the other way around). This harmonizes arguments and parameter forwarding to always use rvalue ref and std::forward in pairs.
This commit is contained in:
parent
49604ca8c8
commit
b72cbb14e3
@ -25,10 +25,10 @@ std::future<RPCLIB_MSGPACK::object_handle> client::async_call(
|
||||
using RPCLIB_MSGPACK::object;
|
||||
LOG_DEBUG("Calling {}", func_name);
|
||||
|
||||
auto args_obj = std::make_tuple(args...);
|
||||
auto args_obj = std::make_tuple(std::forward<Args>(args)...);
|
||||
const int idx = get_next_call_idx();
|
||||
auto call_obj = std::make_tuple(
|
||||
static_cast<uint8_t>(client::request_type::call), idx, func_name, args_obj);
|
||||
static_cast<uint8_t>(client::request_type::call), idx, func_name, std::move(args_obj));
|
||||
|
||||
auto buffer = std::make_shared<RPCLIB_MSGPACK::sbuffer>();
|
||||
RPCLIB_MSGPACK::pack(*buffer, call_obj);
|
||||
@ -55,9 +55,9 @@ void client::send(std::string const& func_name, Args&&... args)
|
||||
RPCLIB_CREATE_LOG_CHANNEL(client)
|
||||
LOG_DEBUG("Sending notification {}", func_name);
|
||||
|
||||
auto args_obj = std::make_tuple(args...);
|
||||
auto args_obj = std::make_tuple(std::forward<Args>(args)...);
|
||||
auto call_obj = std::make_tuple(
|
||||
static_cast<uint8_t>(client::request_type::notification), func_name, args_obj);
|
||||
static_cast<uint8_t>(client::request_type::notification), func_name, std::move(args_obj));
|
||||
|
||||
auto buffer = new RPCLIB_MSGPACK::sbuffer;
|
||||
RPCLIB_MSGPACK::pack(*buffer, call_obj);
|
||||
|
||||
@ -27,7 +27,7 @@ auto call(Functor f, Arg &&arg)
|
||||
template <typename Functor, typename... Args, std::size_t... I>
|
||||
decltype(auto) call_helper(Functor func, std::tuple<Args...> &¶ms,
|
||||
std::index_sequence<I...>) {
|
||||
return func(std::get<I>(params)...);
|
||||
return func(std::forward<Args>(std::get<I>(params))...);
|
||||
}
|
||||
|
||||
//! \brief Calls a functor with arguments provided as a tuple
|
||||
@ -50,7 +50,7 @@ struct call_helper
|
||||
std::tuple<ArgsT...>& args_t,
|
||||
ArgsF&&... args_f)
|
||||
-> decltype(call_helper<N-1>::call(
|
||||
f, args_t, std::get<N-1>(args_t),
|
||||
f, args_t, std::move(std::get<N-1>(args_t)),
|
||||
std::forward<ArgsF>(args_f)...))
|
||||
{
|
||||
return call_helper<N-1>::call(
|
||||
|
||||
@ -32,37 +32,37 @@ public:
|
||||
|
||||
template <typename... Args>
|
||||
void trace(const char *channel, const char *file, const char *func,
|
||||
std::size_t line, const char *msg, Args... args) {
|
||||
std::size_t line, const char *msg, Args&&... args) {
|
||||
(void)func;
|
||||
basic_log("TRACE", channel,
|
||||
RPCLIB_FMT::format("{} ({}:{})",
|
||||
RPCLIB_FMT::format(msg, args...), file,
|
||||
RPCLIB_FMT::format(msg, std::forward<Args>(args)...), file,
|
||||
line));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void debug(const char *channel, const char *file, const char *func,
|
||||
std::size_t line, const char *msg, Args... args) {
|
||||
std::size_t line, const char *msg, Args&&... args) {
|
||||
(void)func;
|
||||
basic_log("DEBUG", channel,
|
||||
RPCLIB_FMT::format("{} ({}:{})",
|
||||
RPCLIB_FMT::format(msg, args...), file,
|
||||
RPCLIB_FMT::format(msg, std::forward<Args>(args)...), file,
|
||||
line));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void warn(const char *channel, const char *msg, Args... args) {
|
||||
basic_log("WARN", channel, RPCLIB_FMT::format(msg, args...));
|
||||
void warn(const char *channel, const char *msg, Args&&... args) {
|
||||
basic_log("WARN", channel, RPCLIB_FMT::format(msg, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void error(const char *channel, const char *msg, Args... args) {
|
||||
basic_log("ERROR", channel, RPCLIB_FMT::format(msg, args...));
|
||||
void error(const char *channel, const char *msg, Args&&... args) {
|
||||
basic_log("ERROR", channel, RPCLIB_FMT::format(msg, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void info(const char *channel, const char *msg, Args... args) {
|
||||
basic_log("INFO", channel, RPCLIB_FMT::format(msg, args...));
|
||||
void info(const char *channel, const char *msg, Args&&... args) {
|
||||
basic_log("INFO", channel, RPCLIB_FMT::format(msg, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -84,7 +84,7 @@ namespace type {
|
||||
|
||||
template <class... Args>
|
||||
inline tuple<Args...> make_tuple(Args&&... args) {
|
||||
return tuple<Args...>(args...);
|
||||
return tuple<Args...>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<class... Args>
|
||||
|
||||
@ -220,7 +220,7 @@ public:
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
T* allocate(Args... args);
|
||||
T* allocate(Args&&... args);
|
||||
|
||||
zone(zone&&) = default;
|
||||
zone& operator=(zone&&) = default;
|
||||
@ -343,7 +343,7 @@ inline void zone::undo_allocate(size_t size)
|
||||
|
||||
|
||||
template <typename T, typename... Args>
|
||||
T* zone::allocate(Args... args)
|
||||
T* zone::allocate(Args&&... args)
|
||||
{
|
||||
void* x = allocate_align(sizeof(T));
|
||||
try {
|
||||
@ -353,7 +353,7 @@ T* zone::allocate(Args... args)
|
||||
throw;
|
||||
}
|
||||
try {
|
||||
return new (x) T(args...);
|
||||
return new (x) T(std::forward<Args>(args)...);
|
||||
} catch (...) {
|
||||
--m_finalizer_array.m_tail;
|
||||
undo_allocate(sizeof(T));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user