triton_cpp v1.2.1
Header-only C++ wrapper for NVIDIA Triton Inference Server clients
Loading...
Searching...
No Matches
triton_cpp::detail::PosixSharedMemory Class Reference

#include <shm.hpp>

Public Member Functions

 PosixSharedMemory (std::string key, std::int64_t size)
 
 PosixSharedMemory (const PosixSharedMemory &)=delete
 
PosixSharedMemoryoperator= (const PosixSharedMemory &)=delete
 
 PosixSharedMemory (PosixSharedMemory &&other) noexcept
 
PosixSharedMemoryoperator= (PosixSharedMemory &&)=delete
 
 ~PosixSharedMemory () noexcept
 
std::uint8_t * address () const noexcept
 
const std::string & key () const noexcept
 

Detailed Description

Owns one mapped POSIX shared-memory object.

Definition at line 20 of file shm.hpp.

Constructor & Destructor Documentation

◆ PosixSharedMemory() [1/3]

triton_cpp::detail::PosixSharedMemory::PosixSharedMemory ( std::string key,
std::int64_t size )
inline

Definition at line 22 of file shm.hpp.

22 : key_{std::move(key)}, size_{size} {
23 fd_ = ::shm_open(key_.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
24 if (fd_ == -1) {
25 throw std::runtime_error("CreateSharedMemoryRegion: unable to get shared memory descriptor for shared-memory key '" + key_ +
26 "'");
27 }
28
29 if (::ftruncate(fd_, size_) == -1) {
30 closeDescriptor();
31 unlinkRegion();
32 throw std::runtime_error("CreateSharedMemoryRegion: unable to initialize shared-memory key '" + key_ +
33 "' to requested size: " + std::to_string(static_cast<std::size_t>(size_)) + " bytes");
34 }
35
36 address_ = ::mmap(nullptr, static_cast<std::size_t>(size_), PROT_READ | PROT_WRITE, MAP_SHARED, fd_, 0);
37 if (address_ == MAP_FAILED) {
38 address_ = nullptr;
39 const int failed_fd = fd_;
40 closeDescriptor();
41 unlinkRegion();
42 throw std::runtime_error("MapSharedMemory: unable to process address space or shared-memory descriptor: " +
43 std::to_string(failed_fd));
44 }
45
46 const int mapped_fd = fd_;
47 if (::close(fd_) == -1) {
48 fd_ = -1;
49 unmapRegion();
50 unlinkRegion();
51 throw std::runtime_error("CloseSharedMemory: unable to close shared-memory descriptor: " + std::to_string(mapped_fd));
52 }
53 fd_ = -1;
54 }
const std::string & key() const noexcept
Definition shm.hpp:75

◆ PosixSharedMemory() [2/3]

triton_cpp::detail::PosixSharedMemory::PosixSharedMemory ( const PosixSharedMemory & )
delete

◆ PosixSharedMemory() [3/3]

triton_cpp::detail::PosixSharedMemory::PosixSharedMemory ( PosixSharedMemory && other)
inlinenoexcept

Definition at line 59 of file shm.hpp.

60 : key_{std::move(other.key_)},
61 address_{std::exchange(other.address_, nullptr)},
62 fd_{std::exchange(other.fd_, -1)},
63 size_{other.size_},
64 owns_name_{std::exchange(other.owns_name_, false)} {}

◆ ~PosixSharedMemory()

triton_cpp::detail::PosixSharedMemory::~PosixSharedMemory ( )
inlinenoexcept

Definition at line 68 of file shm.hpp.

68 {
69 unmapRegion();
70 closeDescriptor();
71 unlinkRegion();
72 }

Member Function Documentation

◆ address()

std::uint8_t * triton_cpp::detail::PosixSharedMemory::address ( ) const
inlinenoexcept

Definition at line 74 of file shm.hpp.

74{ return static_cast<std::uint8_t*>(address_); }

Referenced by triton_cpp::SharedMemoryRegion::getAddress().

◆ key()

const std::string & triton_cpp::detail::PosixSharedMemory::key ( ) const
inlinenoexcept

Definition at line 75 of file shm.hpp.

75{ return key_; }

Referenced by triton_cpp::SharedMemoryRegion::getKey().

◆ operator=() [1/2]

PosixSharedMemory & triton_cpp::detail::PosixSharedMemory::operator= ( const PosixSharedMemory & )
delete

◆ operator=() [2/2]

PosixSharedMemory & triton_cpp::detail::PosixSharedMemory::operator= ( PosixSharedMemory && )
delete

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