CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions
TritonCpuShmResource< IO > Class Template Reference

#include <TritonData.h>

Inheritance diagram for TritonCpuShmResource< IO >:
TritonMemResource< IO >

Public Member Functions

void close () override
 
void copyInput (const void *values, size_t offset) override
 
const uint8_t * copyOutput () override
 
 TritonCpuShmResource (TritonData< IO > *data, const std::string &name, size_t size)
 
 ~TritonCpuShmResource () override
 
- Public Member Functions inherited from TritonMemResource< IO >
uint8_t * addr ()
 
virtual void set ()
 
size_t size () const
 
 TritonMemResource (TritonData< IO > *data, const std::string &name, size_t size)
 
virtual ~TritonMemResource ()
 

Additional Inherited Members

- Protected Attributes inherited from TritonMemResource< IO >
uint8_t * addr_
 
bool closed_
 
TritonData< IO > * data_
 
std::string name_
 
size_t size_
 

Detailed Description

template<typename IO>
class TritonCpuShmResource< IO >

Definition at line 25 of file TritonData.h.

Constructor & Destructor Documentation

template<typename IO >
TritonCpuShmResource< IO >::TritonCpuShmResource ( TritonData< IO > *  data,
const std::string &  name,
size_t  size 
)

Definition at line 54 of file TritonMemResource.cc.

References TritonMemResource< IO >::addr_, TritonCpuShmResource< IO >::close(), TritonMemResource< IO >::data_, Exception, TritonMemResource< IO >::name_, hltrates_dqm_sourceclient-live_cfg::offset, TritonMemResource< IO >::size_, and triton_utils::throwIfError().

56  //get shared memory region descriptor
57  int shm_fd = shm_open(this->name_.c_str(), O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
58  if (shm_fd == -1)
59  throw cms::Exception("TritonError") << "unable to get shared memory descriptor for key: " + this->name_;
60 
61  //extend shared memory object
62  int res = ftruncate(shm_fd, this->size_);
63  if (res == -1)
64  throw cms::Exception("TritonError") << "unable to initialize shared memory key " + this->name_ +
65  " to requested size: " + std::to_string(this->size_);
66 
67  //map to process address space
68  constexpr size_t offset(0);
69  this->addr_ = (uint8_t*)mmap(nullptr, this->size_, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, offset);
70  if (this->addr_ == MAP_FAILED)
71  throw cms::Exception("TritonError") << "unable to map to process address space for shared memory key: " +
72  this->name_;
73 
74  //close descriptor
75  if (::close(shm_fd) == -1)
76  throw cms::Exception("TritonError") << "unable to close descriptor for shared memory key: " + this->name_;
77 
78  triton_utils::throwIfError(this->data_->client()->RegisterSystemSharedMemory(this->name_, this->name_, this->size_),
79  "unable to register shared memory region: " + this->name_);
80 }
TritonData< IO > * data_
void throwIfError(const Error &err, std::string_view msg)
Definition: triton_utils.cc:21
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
size_t size() const
template<typename IO >
TritonCpuShmResource< IO >::~TritonCpuShmResource< IO > ( )
override

Definition at line 83 of file TritonMemResource.cc.

83  {
84  close();
85 }

Member Function Documentation

template<typename IO >
void TritonCpuShmResource< IO >::close ( void  )
overridevirtual

Reimplemented from TritonMemResource< IO >.

Definition at line 88 of file TritonMemResource.cc.

References Exception, and triton_utils::throwIfError().

Referenced by esMonitoring.AsyncLineReaderMixin::handle_close(), esMonitoring.FDJsonServer::handle_close(), and TritonCpuShmResource< IO >::TritonCpuShmResource().

88  {
89  if (this->closed_)
90  return;
91 
92  triton_utils::throwIfError(this->data_->client()->UnregisterSystemSharedMemory(this->name_),
93  "unable to unregister shared memory region: " + this->name_);
94 
95  //unmap
96  int tmp_fd = munmap(this->addr_, this->size_);
97  if (tmp_fd == -1)
98  throw cms::Exception("TritonError") << "unable to munmap for shared memory key: " << this->name_;
99 
100  //unlink
101  int shm_fd = shm_unlink(this->name_.c_str());
102  if (shm_fd == -1)
103  throw cms::Exception("TritonError") << "unable to unlink for shared memory key: " << this->name_;
104 
105  this->closed_ = true;
106 }
TritonData< IO > * data_
void throwIfError(const Error &err, std::string_view msg)
Definition: triton_utils.cc:21
void TritonInputCpuShmResource::copyInput ( const void *  values,
size_t  offset 
)
inlineoverridevirtual

Reimplemented from TritonMemResource< IO >.

Definition at line 53 of file TritonMemResource.h.

53 {}
const uint8_t * TritonOutputCpuShmResource::copyOutput ( )
inlineoverridevirtual

Reimplemented from TritonMemResource< IO >.

Definition at line 54 of file TritonMemResource.h.

54 { return nullptr; }