MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
FabricInstance.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Contributors to the Media eXchange Layer project.
2//
3// SPDX-License-Identifier: Apache-2.0
4
5#include "FabricInstance.hpp"
6#include <cstdlib> // IWYU pragma: keep // for ::setenv
8#include "mxl/fabrics.h"
9#include "Exception.hpp"
10#include "FILogging.hpp"
11#include "Initiator.hpp"
12#include "Target.hpp"
13
15{
17 : _mu{}
18 , _mxlInstance(instance)
19 {
20 // Disable memory registration cache: Since we only perform memory registration during initialization rather than runtime, the cache provides
21 // no benefit for our use case.
22 ::setenv("FI_MR_CACHE_MONITOR", "disabled", 1);
23
25 }
26
28 {
29 return reinterpret_cast<mxlFabricsInstance>(this);
30 }
31
33 {
34 return reinterpret_cast<FabricsInstance*>(instance);
35 }
36
38 {
39 auto lock = std::unique_lock{_mu};
40 return &_targets.emplace_back();
41 }
42
44 {
45 auto lock = std::unique_lock{_mu};
46 return &_initiators.emplace_back();
47 }
48
50 {
51 auto lock = std::unique_lock{_mu};
52 if (!_targets.remove_if([&](TargetWrapper const& lhs) { return &lhs == wrapper; }))
53 {
54 throw Exception::make(MXL_ERR_INVALID_ARG, "Target to remove is not known to instance");
55 }
56 }
57
59 {
60 auto lock = std::unique_lock{_mu};
61 if (!_initiators.remove_if([&](InitiatorWrapper const& lhs) { return &lhs == initiator; }))
62 {
63 throw Exception::make(MXL_ERR_INVALID_ARG, "Initiator to remove is not known to instance");
64 }
65 }
66
67}
static Exception make(mxlStatus status, fmt::format_string< T... > fmt, T &&... args)
Make any type of exception.
Definition Exception.hpp:35
TargetWrapper * createTarget()
Create an uninitialized Target associated with this instance.
static FabricsInstance * fromAPI(mxlFabricsInstance instance) noexcept
Convert an mxlFabricsInstance API object to its underlying FabricsInstance.
InitiatorWrapper * createInitiator()
create an uninitialized Initiator associated with this instance.
void destroyInitiator(InitiatorWrapper *initiator)
Destroy an Initiator associated with this instance.
FabricsInstance(mxl::lib::Instance *instance)
Create a FabricsInstance associated with the given MXL Instance.
void destroyTarget(TargetWrapper *target)
Destroy a Target associated with this instance.
std::list< InitiatorWrapper > _initiators
mxlFabricsInstance toAPI() noexcept
Convert this FabricsInstance to its API representation.
A wrapper around Initiator implementations.
A wrapper around Target implementations.
Definition Target.hpp:99
struct mxlFabricsInstance_t * mxlFabricsInstance
Definition fabrics.h:29
@ MXL_ERR_INVALID_ARG
Definition mxl.h:35
void fiInitLogging()
Initalize logging for libfabric. After this call, all libfabric internal logs will be written to the ...