MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
EventQueue.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 Contributors to the Media eXchange Layer project.
2//
3// SPDX-License-Identifier: Apache-2.0
4
5#pragma once
6
7#include <chrono>
8#include <memory>
9#include <rdma/fabric.h>
10#include <rdma/fi_eq.h>
11#include "Event.hpp"
12#include "Fabric.hpp"
13
15{
18 class EventQueue : public std::enable_shared_from_this<EventQueue>
19 {
20 public:
23 struct Attributes final
24 {
25 public:
28 static Attributes defaults();
29
32 [[nodiscard]]
33 ::fi_eq_attr raw() const noexcept;
34
35 public:
36 std::size_t size;
37 };
38
39 public:
42 static std::shared_ptr<EventQueue> open(std::shared_ptr<Fabric>, Attributes const& attr = Attributes::defaults());
43
45
46 // No copying, no moving
47 EventQueue(EventQueue const&) = delete;
48 void operator=(EventQueue const&) = delete;
51
54 ::fid_eq* raw() noexcept;
55
58 [[nodiscard]]
59 ::fid_eq const* raw() const noexcept;
60
64 std::optional<Event> read();
65
73 std::optional<Event> readBlocking(std::chrono::steady_clock::duration timeout);
74
75 private:
78 void close();
79
86 EventQueue(::fid_eq* raw, std::shared_ptr<Fabric> fabric);
87
92 std::optional<Event> handleReadResult(ssize_t, std::uint32_t, ::fi_eq_entry const&);
93
94 private:
95 ::fid_eq* _raw;
96 std::shared_ptr<Fabric> _fabric;
97 };
98}
std::optional< Event > handleReadResult(ssize_t, std::uint32_t, ::fi_eq_entry const &)
Handle the result of a blocking or non-blocking read.
void operator=(EventQueue const &)=delete
void close()
Releases all underlying resources. This is called from the destructor and the move-assignment operato...
std::shared_ptr< Fabric > _fabric
std::optional< Event > readBlocking(std::chrono::steady_clock::duration timeout)
Perform a blocking read on the event queue.
::fid_eq * raw() noexcept
Returns a raw handle to the event queue.
EventQueue(EventQueue const &)=delete
static std::shared_ptr< EventQueue > open(std::shared_ptr< Fabric >, Attributes const &attr=Attributes::defaults())
Create a new event queue associated with the specified fabric.
std::optional< Event > read()
Perform a non-blocking read on the event queue. If no event is available in the queue,...
EventQueue & operator=(EventQueue &&)=delete
EventQueue(EventQueue &&)=delete
Type to represent an event entry from an EventQueue.
Definition Event.hpp:21
RAIII wrapper around a libfabric fabric object (fid_fabric).
Definition Fabric.hpp:17
Attributes to configure newly created event queues.
static Attributes defaults()
Creates a configuration with all values set to reasonable defaults.
::fi_eq_attr raw() const noexcept
Returns the raw libfabric version of this object.