MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
mxl::lib::fabrics::ofi::Completion Class Reference

Type to represent a completion entry from a CompletionQueue. More...

#include <Completion.hpp>

Classes

class  Data
 Data variant of the completion entry instance. More...
class  Error
 Error variant of the completion entry instance. More...

Public Types

using Token = std::uintptr_t
 A token used to associate a completion entry with an endpoint.

Public Member Functions

 Completion (Data entry)
 Completion (Error entry)
Data data () const
 Accessor for the data variant. Calling this on an error entry will throw.
Error err () const
 Accessor for the error variant. Calling this on a data entry will throw.
bool isDataEntry () const noexcept
 Check whether this is a data entry.
bool isErrEntry () const noexcept
 check whether this is an error entry
Token token () const noexcept
 Get the token that was associated with the operation that has completed.
std::optional< Data > tryData () const noexcept
 Attempt to access the data variant. Returns std::nullopt if this is an error entry.
std::optional< Error > tryErr () const noexcept
 Attempt to access the error variant. Returns std::nullopt if this is a data entry.

Static Public Member Functions

static Token randomToken ()
static constexpr Token tokenFromContextValue (void *contextValue) noexcept
 Convert between completion tokens and context values that can be written to and read from raw libfabric queue entries.
static constexpr void * tokenToContextValue (Token token) noexcept
 Convert between completion tokens and context values that can be written to and read from raw libfabric queue entries.

Private Types

using Inner = std::variant<Data, Error>

Private Attributes

Inner _inner

Friends

class CompletionQueue

Detailed Description

Type to represent a completion entry from a CompletionQueue.

Definition at line 21 of file Completion.hpp.

Member Typedef Documentation

◆ Inner

using mxl::lib::fabrics::ofi::Completion::Inner = std::variant<Data, Error>
private

Definition at line 153 of file Completion.hpp.

◆ Token

A token used to associate a completion entry with an endpoint.

Definition at line 26 of file Completion.hpp.

Constructor & Destructor Documentation

◆ Completion() [1/2]

mxl::lib::fabrics::ofi::Completion::Completion ( Data entry)
explicit

Definition at line 73 of file Completion.cpp.

74 : _inner(entry)
75 {}

◆ Completion() [2/2]

mxl::lib::fabrics::ofi::Completion::Completion ( Error entry)
explicit

Definition at line 77 of file Completion.cpp.

78 : _inner(entry)
79 {}

Member Function Documentation

◆ data()

Completion::Data mxl::lib::fabrics::ofi::Completion::data ( ) const
nodiscard

Accessor for the data variant. Calling this on an error entry will throw.

Definition at line 58 of file Completion.cpp.

59 {
60 if (auto data = std::get_if<Completion::Data>(&_inner); data)
61 {
62 return *data;
63 }
64
65 throw Exception::invalidState("Failed to unwrap completion queue entry as data entry.");
66 }
Data data() const
Accessor for the data variant. Calling this on an error entry will throw.
static Exception invalidState(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_STATE exception.
Definition Exception.hpp:59

◆ err()

Completion::Error mxl::lib::fabrics::ofi::Completion::err ( ) const
nodiscard

Accessor for the error variant. Calling this on a data entry will throw.

Definition at line 90 of file Completion.cpp.

91 {
92 if (auto error = std::get_if<Error>(&_inner); error)
93 {
94 return *error;
95 }
96
97 throw Exception::invalidState("Failed to unwrap completion queue entry as error.");
98 }

◆ isDataEntry()

bool mxl::lib::fabrics::ofi::Completion::isDataEntry ( ) const
nodiscardnoexcept

Check whether this is a data entry.

Definition at line 120 of file Completion.cpp.

121 {
122 return std::holds_alternative<Data>(_inner);
123 }

◆ isErrEntry()

bool mxl::lib::fabrics::ofi::Completion::isErrEntry ( ) const
nodiscardnoexcept

check whether this is an error entry

Definition at line 125 of file Completion.cpp.

126 {
127 return std::holds_alternative<Error>(_inner);
128 }

◆ randomToken()

Completion::Token mxl::lib::fabrics::ofi::Completion::randomToken ( )
staticnodiscard

Definition at line 81 of file Completion.cpp.

82 {
83 std::uniform_int_distribution<Completion::Token> dist;
84 std::random_device rd;
85 std::mt19937 eng{rd()};
86
87 return dist(eng);
88 }

◆ token()

Completion::Token mxl::lib::fabrics::ofi::Completion::token ( ) const
nodiscardnoexcept

Get the token that was associated with the operation that has completed.

Definition at line 130 of file Completion.cpp.

131 {
132 return std::visit(
133 overloaded{
134 [](Completion::Data const& data) { return data.token(); },
135 [](Completion::Error const& err) { return err.token(); },
136 },
137 _inner);
138 }
Error err() const
Accessor for the error variant. Calling this on a data entry will throw.

◆ tokenFromContextValue()

constexpr Token mxl::lib::fabrics::ofi::Completion::tokenFromContextValue ( void * contextValue)
inlinestaticnodiscardconstexprnoexcept

Convert between completion tokens and context values that can be written to and read from raw libfabric queue entries.

Definition at line 109 of file Completion.hpp.

110 {
111 return std::bit_cast<Token>(contextValue);
112 }

◆ tokenToContextValue()

constexpr void * mxl::lib::fabrics::ofi::Completion::tokenToContextValue ( Token token)
inlinestaticnodiscardconstexprnoexcept

Convert between completion tokens and context values that can be written to and read from raw libfabric queue entries.

Definition at line 101 of file Completion.hpp.

102 {
103 return std::bit_cast<void*>(token);
104 }
Token token() const noexcept
Get the token that was associated with the operation that has completed.

◆ tryData()

std::optional< Completion::Data > mxl::lib::fabrics::ofi::Completion::tryData ( ) const
nodiscardnoexcept

Attempt to access the data variant. Returns std::nullopt if this is an error entry.

Definition at line 100 of file Completion.cpp.

101 {
102 if (auto data = std::get_if<Data>(&_inner); data)
103 {
104 return {*data};
105 }
106
107 return std::nullopt;
108 }

◆ tryErr()

std::optional< Completion::Error > mxl::lib::fabrics::ofi::Completion::tryErr ( ) const
nodiscardnoexcept

Attempt to access the error variant. Returns std::nullopt if this is a data entry.

Definition at line 110 of file Completion.cpp.

111 {
112 if (auto error = std::get_if<Error>(&_inner); error)
113 {
114 return {*error};
115 }
116
117 return std::nullopt;
118 }

◆ CompletionQueue

friend class CompletionQueue
friend

Definition at line 151 of file Completion.hpp.

Member Data Documentation

◆ _inner

Inner mxl::lib::fabrics::ofi::Completion::_inner
private

Definition at line 156 of file Completion.hpp.


The documentation for this class was generated from the following files: