MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
CompletionQueue.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 <optional>
10#include <rdma/fi_eq.h>
11#include "Completion.hpp"
12#include "Domain.hpp"
13
15{
16
19 class CompletionQueue : public std::enable_shared_from_this<CompletionQueue>
20 {
21 public:
26 {
27 public:
29 constexpr static std::size_t DEFAULT_SIZE = 8;
30
34 static Attributes defaults();
35
38 [[nodiscard]]
39 ::fi_cq_attr raw() const noexcept;
40
41 public:
42 std::size_t size;
43 enum fi_wait_obj waitObject;
44 };
45
48 static bool isWaitObjectSupportedForEFA() noexcept;
49
50 public:
53 static std::shared_ptr<CompletionQueue> open(std::shared_ptr<Domain> domain, Attributes const& attr = Attributes::defaults());
54
56
57 // No copying, no moving
59 void operator=(CompletionQueue const&) = delete;
61 CompletionQueue& operator=(CompletionQueue&&) = delete;
62
65 ::fid_cq* raw() noexcept;
66
69 [[nodiscard]]
70 ::fid_cq const* raw() const noexcept;
71
77 std::optional<Completion> read();
78
86 std::optional<Completion> readBlocking(std::chrono::steady_clock::duration timeout);
87
88 private:
91 void close();
92
99 CompletionQueue(::fid_cq* raw, std::shared_ptr<Domain> domain);
100
105 std::optional<Completion> handleReadResult(ssize_t ret, ::fi_cq_data_entry const& entry);
106
107 private:
108 ::fid_cq* _raw;
109 std::shared_ptr<Domain> _domain;
110 };
111}
static std::shared_ptr< CompletionQueue > open(std::shared_ptr< Domain > domain, Attributes const &attr=Attributes::defaults())
Create a new completion queue in the specified domain.
::fid_cq * raw() noexcept
Mutable accessor of the underlying fi_cq instance.
CompletionQueue(CompletionQueue const &)=delete
void close()
Releases all underlying resources. This is called from the destructor and the move-assignment operato...
static bool isWaitObjectSupportedForEFA() noexcept
Check if wait any wait object type supported by the EFA provider for this libfabric version.
std::optional< Completion > readBlocking(std::chrono::steady_clock::duration timeout)
Perform a blocking read on the completion queue.
std::optional< Completion > handleReadResult(ssize_t ret, ::fi_cq_data_entry const &entry)
Handle the result of a blocking or non-blocking read.
std::optional< Completion > read()
Perform a non-blocking read on the completion queue.
Type to represent a completion entry from a CompletionQueue.
RAII Wrapper around a libfabric domain (fi_domain).
Definition Domain.hpp:24
A collection of attributes that can be used to configure the operation of newly created completion qu...
static constexpr std::size_t DEFAULT_SIZE
The completion-queue depth used when no explicit depth is requested.
::fi_cq_attr raw() const noexcept
Returns the raw libfabric version of this object.
static Attributes defaults()
Returns the a CompletionQueueAttr with all of its attributes set to reasonable defaults.