mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 17:41:45 +00:00
Implement parallel ofi::Socket::Send
This commit is contained in:
committed by
Dennis Klein
parent
9ae48c21f5
commit
46e2420547
@@ -9,17 +9,28 @@
|
||||
#ifndef FAIR_MQ_OFI_CONTROLMESSAGES_H
|
||||
#define FAIR_MQ_OFI_CONTROLMESSAGES_H
|
||||
|
||||
#include <FairMQLogger.h>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace ofi
|
||||
namespace boost {
|
||||
namespace asio {
|
||||
|
||||
template<typename PodType>
|
||||
auto buffer(const PodType& obj) -> boost::asio::const_buffer
|
||||
{
|
||||
return boost::asio::const_buffer(static_cast<const void*>(&obj), sizeof(PodType));
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
} // namespace boost
|
||||
|
||||
namespace fair {
|
||||
namespace mq {
|
||||
namespace ofi {
|
||||
|
||||
enum class ControlMessageType
|
||||
{
|
||||
@@ -28,59 +39,38 @@ enum class ControlMessageType
|
||||
PostBufferAcknowledgement
|
||||
};
|
||||
|
||||
struct ControlMessage {
|
||||
struct ControlMessage
|
||||
{
|
||||
ControlMessageType type;
|
||||
};
|
||||
|
||||
struct DataAddressAnnouncement : ControlMessage {
|
||||
uint32_t ipv4; // in_addr_t from <netinet/in.h>
|
||||
uint32_t port; // in_port_t from <netinet/in.h>
|
||||
};
|
||||
|
||||
struct PostBuffer : ControlMessage {
|
||||
uint64_t size; // buffer size (size_t)
|
||||
};
|
||||
|
||||
struct PostBufferAcknowledgement {
|
||||
uint64_t size; // size_t
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
using CtrlMsgPtr = std::unique_ptr<T, std::function<void(T*)>>;
|
||||
|
||||
template<typename T, typename A, typename ... Args>
|
||||
auto MakeControlMessage(A* pmr, Args&& ... args) -> CtrlMsgPtr<T>
|
||||
struct DataAddressAnnouncement : ControlMessage
|
||||
{
|
||||
void* raw_mem = pmr->allocate(sizeof(T));
|
||||
T* raw_ptr = new (raw_mem) T(std::forward<Args>(args)...);
|
||||
uint32_t ipv4; // in_addr_t from <netinet/in.h>
|
||||
uint32_t port; // in_port_t from <netinet/in.h>
|
||||
};
|
||||
|
||||
struct PostBuffer : ControlMessage
|
||||
{
|
||||
uint64_t size; // buffer size (size_t)
|
||||
};
|
||||
|
||||
template<typename T, typename... Args>
|
||||
auto MakeControlMessage(Args&&... args) -> T
|
||||
{
|
||||
T ctrl = T(std::forward<Args>(args)...);
|
||||
|
||||
if (std::is_same<T, DataAddressAnnouncement>::value) {
|
||||
raw_ptr->type = ControlMessageType::DataAddressAnnouncement;
|
||||
ctrl.type = ControlMessageType::DataAddressAnnouncement;
|
||||
} else if (std::is_same<T, PostBuffer>::value) {
|
||||
raw_ptr->type = ControlMessageType::PostBuffer;
|
||||
ctrl.type = ControlMessageType::PostBuffer;
|
||||
}
|
||||
|
||||
return {raw_ptr, [=](T* p) { pmr->deallocate(p, sizeof(T)); }};
|
||||
return ctrl;
|
||||
}
|
||||
|
||||
template<typename Derived, typename Base, typename Del>
|
||||
auto StaticUniquePtrDowncast(std::unique_ptr<Base, Del>&& p) -> std::unique_ptr<Derived, Del>
|
||||
{
|
||||
auto down = static_cast<Derived*>(p.release());
|
||||
return std::unique_ptr<Derived, Del>(down, std::move(p.get_deleter()));
|
||||
}
|
||||
|
||||
template<typename Base, typename Derived, typename Del>
|
||||
auto StaticUniquePtrUpcast(std::unique_ptr<Derived, Del>&& p) -> std::unique_ptr<Base, std::function<void(Base*)>>
|
||||
{
|
||||
auto up = static_cast<Base*>(p.release());
|
||||
return {up, [deleter = std::move(p.get_deleter())](Base* ptr) {
|
||||
deleter(static_cast<Derived*>(ptr));
|
||||
}};
|
||||
}
|
||||
|
||||
} /* namespace ofi */
|
||||
} /* namespace mq */
|
||||
} /* namespace fair */
|
||||
} // namespace ofi
|
||||
} // namespace mq
|
||||
} // namespace fair
|
||||
|
||||
#endif /* FAIR_MQ_OFI_CONTROLMESSAGES_H */
|
||||
|
Reference in New Issue
Block a user