Replace tools::make_unique with std::make_unique

This commit is contained in:
Alexey Rybalchenko
2021-01-13 13:36:47 +01:00
parent 6815c9c172
commit 751c53171c
15 changed files with 85 additions and 103 deletions

View File

@@ -9,7 +9,6 @@
#ifndef FAIR_MQ_ZMQ_MESSAGE_H
#define FAIR_MQ_ZMQ_MESSAGE_H
#include <fairmq/Tools.h>
#include <fairmq/zeromq/UnmanagedRegion.h>
#include <FairMQLogger.h>
#include <FairMQMessage.h>
@@ -20,7 +19,7 @@
#include <cstddef>
#include <cstdlib> // malloc
#include <cstring>
#include <memory>
#include <memory> // make_unique
#include <new> // bad_alloc
#include <string>
@@ -41,7 +40,7 @@ class Message final : public fair::mq::Message
Message(FairMQTransportFactory* factory = nullptr)
: fair::mq::Message(factory)
, fAlignment(0)
, fMsg(tools::make_unique<zmq_msg_t>())
, fMsg(std::make_unique<zmq_msg_t>())
{
if (zmq_msg_init(fMsg.get()) != 0) {
LOG(error) << "failed initializing message, reason: " << zmq_strerror(errno);
@@ -51,7 +50,7 @@ class Message final : public fair::mq::Message
Message(Alignment alignment, FairMQTransportFactory* factory = nullptr)
: fair::mq::Message(factory)
, fAlignment(alignment.alignment)
, fMsg(tools::make_unique<zmq_msg_t>())
, fMsg(std::make_unique<zmq_msg_t>())
{
if (zmq_msg_init(fMsg.get()) != 0) {
LOG(error) << "failed initializing message, reason: " << zmq_strerror(errno);
@@ -61,7 +60,7 @@ class Message final : public fair::mq::Message
Message(const size_t size, FairMQTransportFactory* factory = nullptr)
: fair::mq::Message(factory)
, fAlignment(0)
, fMsg(tools::make_unique<zmq_msg_t>())
, fMsg(std::make_unique<zmq_msg_t>())
{
if (zmq_msg_init_size(fMsg.get(), size) != 0) {
LOG(error) << "failed initializing message with size, reason: " << zmq_strerror(errno);
@@ -85,7 +84,7 @@ class Message final : public fair::mq::Message
Message(const size_t size, Alignment alignment, FairMQTransportFactory* factory = nullptr)
: fair::mq::Message(factory)
, fAlignment(alignment.alignment)
, fMsg(tools::make_unique<zmq_msg_t>())
, fMsg(std::make_unique<zmq_msg_t>())
{
if (fAlignment != 0) {
auto ptrs = AllocateAligned(size, fAlignment);
@@ -102,7 +101,7 @@ class Message final : public fair::mq::Message
Message(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr, FairMQTransportFactory* factory = nullptr)
: fair::mq::Message(factory)
, fAlignment(0)
, fMsg(tools::make_unique<zmq_msg_t>())
, fMsg(std::make_unique<zmq_msg_t>())
{
if (zmq_msg_init_data(fMsg.get(), data, size, ffn, hint) != 0) {
LOG(error) << "failed initializing message with data, reason: " << zmq_strerror(errno);
@@ -112,7 +111,7 @@ class Message final : public fair::mq::Message
Message(UnmanagedRegionPtr& region, void* data, const size_t size, void* hint = 0, FairMQTransportFactory* factory = nullptr)
: fair::mq::Message(factory)
, fAlignment(0)
, fMsg(tools::make_unique<zmq_msg_t>())
, fMsg(std::make_unique<zmq_msg_t>())
{
// FIXME: make this zero-copy:
// simply taking over the provided buffer can casue premature delete, since region could be
@@ -140,7 +139,7 @@ class Message final : public fair::mq::Message
void Rebuild() override
{
CloseMessage();
fMsg = tools::make_unique<zmq_msg_t>();
fMsg = std::make_unique<zmq_msg_t>();
if (zmq_msg_init(fMsg.get()) != 0) {
LOG(error) << "failed initializing message, reason: " << zmq_strerror(errno);
}
@@ -150,7 +149,7 @@ class Message final : public fair::mq::Message
{
CloseMessage();
fAlignment = alignment.alignment;
fMsg = tools::make_unique<zmq_msg_t>();
fMsg = std::make_unique<zmq_msg_t>();
if (zmq_msg_init(fMsg.get()) != 0) {
LOG(error) << "failed initializing message, reason: " << zmq_strerror(errno);
}
@@ -159,7 +158,7 @@ class Message final : public fair::mq::Message
void Rebuild(const size_t size) override
{
CloseMessage();
fMsg = tools::make_unique<zmq_msg_t>();
fMsg = std::make_unique<zmq_msg_t>();
if (zmq_msg_init_size(fMsg.get(), size) != 0) {
LOG(error) << "failed initializing message with size, reason: " << zmq_strerror(errno);
}
@@ -169,7 +168,7 @@ class Message final : public fair::mq::Message
{
CloseMessage();
fAlignment = alignment.alignment;
fMsg = tools::make_unique<zmq_msg_t>();
fMsg = std::make_unique<zmq_msg_t>();
if (fAlignment != 0) {
auto ptrs = AllocateAligned(size, fAlignment);
@@ -186,7 +185,7 @@ class Message final : public fair::mq::Message
void Rebuild(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) override
{
CloseMessage();
fMsg = tools::make_unique<zmq_msg_t>();
fMsg = std::make_unique<zmq_msg_t>();
if (zmq_msg_init_data(fMsg.get(), data, size, ffn, hint) != 0) {
LOG(error) << "failed initializing message with data, reason: " << zmq_strerror(errno);
}
@@ -217,7 +216,7 @@ class Message final : public fair::mq::Message
LOG(error) << "cannot set used size higher than original.";
return false;
} else {
auto newMsg = tools::make_unique<zmq_msg_t>();
auto newMsg = std::make_unique<zmq_msg_t>();
void* data = GetData();
if (zmq_msg_init_data(newMsg.get(), data, size, [](void* /* data */, void* obj) {
zmq_msg_close(static_cast<zmq_msg_t*>(obj));

View File

@@ -19,7 +19,7 @@
#include <zmq.h>
#include <atomic>
#include <memory> // unique_ptr
#include <memory> // unique_ptr, make_unique
namespace fair {
namespace mq {
@@ -258,7 +258,7 @@ class Socket final : public fair::mq::Socket
bool repeat = false;
do {
FairMQMessagePtr part = tools::make_unique<Message>(GetTransport());
FairMQMessagePtr part = std::make_unique<Message>(GetTransport());
int nbytes = zmq_msg_recv(static_cast<Message*>(part.get())->GetMessage(), fSocket, flags);
if (nbytes >= 0) {
@@ -328,8 +328,7 @@ class Socket final : public fair::mq::Socket
{
size_t eventsSize = sizeof(uint32_t);
if (zmq_getsockopt(fSocket, ZMQ_EVENTS, events, &eventsSize) < 0) {
throw SocketError(
tools::ToString("failed setting ZMQ_EVENTS, reason: ", zmq_strerror(errno)));
throw SocketError(tools::ToString("failed setting ZMQ_EVENTS, reason: ", zmq_strerror(errno)));
}
}

View File

@@ -18,7 +18,7 @@
#include <FairMQTransportFactory.h>
#include <fairmq/ProgOptions.h>
#include <memory> // unique_ptr
#include <memory> // unique_ptr, make_unique
#include <string>
#include <vector>
@@ -41,10 +41,10 @@ class TransportFactory final : public FairMQTransportFactory
LOG(debug) << "Transport: Using ZeroMQ library, version: " << major << "." << minor << "." << patch;
if (config) {
fCtx = tools::make_unique<Context>(config->GetProperty<int>("io-threads", 1));
fCtx = std::make_unique<Context>(config->GetProperty<int>("io-threads", 1));
} else {
LOG(debug) << "fair::mq::ProgOptions not available! Using defaults.";
fCtx = tools::make_unique<Context>(1);
fCtx = std::make_unique<Context>(1);
}
}
@@ -53,52 +53,52 @@ class TransportFactory final : public FairMQTransportFactory
MessagePtr CreateMessage() override
{
return tools::make_unique<Message>(this);
return std::make_unique<Message>(this);
}
MessagePtr CreateMessage(Alignment alignment) override
{
return tools::make_unique<Message>(alignment, this);
return std::make_unique<Message>(alignment, this);
}
MessagePtr CreateMessage(const size_t size) override
{
return tools::make_unique<Message>(size, this);
return std::make_unique<Message>(size, this);
}
MessagePtr CreateMessage(const size_t size, Alignment alignment) override
{
return tools::make_unique<Message>(size, alignment, this);
return std::make_unique<Message>(size, alignment, this);
}
MessagePtr CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) override
{
return tools::make_unique<Message>(data, size, ffn, hint, this);
return std::make_unique<Message>(data, size, ffn, hint, this);
}
MessagePtr CreateMessage(UnmanagedRegionPtr& region, void* data, const size_t size, void* hint = 0) override
{
return tools::make_unique<Message>(region, data, size, hint, this);
return std::make_unique<Message>(region, data, size, hint, this);
}
SocketPtr CreateSocket(const std::string& type, const std::string& name) override
{
return tools::make_unique<Socket>(*fCtx, type, name, GetId(), this);
return std::make_unique<Socket>(*fCtx, type, name, GetId(), this);
}
PollerPtr CreatePoller(const std::vector<FairMQChannel>& channels) const override
{
return tools::make_unique<Poller>(channels);
return std::make_unique<Poller>(channels);
}
PollerPtr CreatePoller(const std::vector<FairMQChannel*>& channels) const override
{
return tools::make_unique<Poller>(channels);
return std::make_unique<Poller>(channels);
}
PollerPtr CreatePoller(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList) const override
{
return tools::make_unique<Poller>(channelsMap, channelList);
return std::make_unique<Poller>(channelsMap, channelList);
}
UnmanagedRegionPtr CreateUnmanagedRegion(const size_t size, RegionCallback callback, const std::string& path = "", int flags = 0) override
@@ -123,7 +123,7 @@ class TransportFactory final : public FairMQTransportFactory
UnmanagedRegionPtr CreateUnmanagedRegion(const size_t size, const int64_t userFlags, RegionCallback callback, RegionBulkCallback bulkCallback, const std::string&, int)
{
UnmanagedRegionPtr ptr = tools::make_unique<UnmanagedRegion>(*fCtx, size, userFlags, callback, bulkCallback, this);
UnmanagedRegionPtr ptr = std::make_unique<UnmanagedRegion>(*fCtx, size, userFlags, callback, bulkCallback, this);
auto zPtr = static_cast<UnmanagedRegion*>(ptr.get());
fCtx->AddRegion(false, zPtr->GetId(), zPtr->GetData(), zPtr->GetSize(), zPtr->GetUserFlags(), RegionEvent::created);
return ptr;