CMS 3D CMS Logo

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 27 of file TritonData.h.

Constructor & Destructor Documentation

◆ TritonCpuShmResource()

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

Definition at line 53 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_, cond::impl::to_string(), and TRITON_THROW_IF_ERROR.

55  //mmap of size zero is required to fail by POSIX, but still need to have some shared memory region available for Triton
56  this->size_ = std::max<size_t>(this->size_, 1);
57 
58  //get shared memory region descriptor
59  int shm_fd = shm_open(this->name_.c_str(), O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
60  if (shm_fd == -1)
61  throw cms::Exception("TritonError") << "unable to get shared memory descriptor for key: " + this->name_;
62 
63  //extend shared memory object
64  int res = ftruncate(shm_fd, this->size_);
65  if (res == -1)
66  throw cms::Exception("TritonError") << "unable to initialize shared memory key " + this->name_ +
67  " to requested size: " + std::to_string(this->size_);
68 
69  //map to process address space
70  constexpr size_t offset(0);
71  this->addr_ = (uint8_t*)mmap(nullptr, this->size_, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, offset);
72  if (this->addr_ == MAP_FAILED)
73  throw cms::Exception("TritonError") << "unable to map to process address space for shared memory key: " +
74  this->name_;
75 
76  //close descriptor
77  if (::close(shm_fd) == -1)
78  throw cms::Exception("TritonError") << "unable to close descriptor for shared memory key: " + this->name_;
79 
80  TRITON_THROW_IF_ERROR(this->data_->client()->RegisterSystemSharedMemory(this->name_, this->name_, this->size_),
81  "unable to register shared memory region: " + this->name_);
82 }
#define TRITON_THROW_IF_ERROR(X, MSG)
Definition: triton_utils.h:75
TritonData< IO > * data_
std::string to_string(const V &value)
Definition: OMSAccess.h:77
Definition: Electron.h:6
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
size_t size() const

◆ ~TritonCpuShmResource()

template<typename IO >
TritonCpuShmResource< IO >::~TritonCpuShmResource< IO > ( )
override

Definition at line 85 of file TritonMemResource.cc.

85  {
86  close();
87 }

Member Function Documentation

◆ close()

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

Reimplemented from TritonMemResource< IO >.

Definition at line 90 of file TritonMemResource.cc.

References Exception, and TRITON_THROW_IF_ERROR.

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

90  {
91  if (this->closed_)
92  return;
93 
94  TRITON_THROW_IF_ERROR(this->data_->client()->UnregisterSystemSharedMemory(this->name_),
95  "unable to unregister shared memory region: " + this->name_);
96 
97  //unmap
98  int tmp_fd = munmap(this->addr_, this->size_);
99  if (tmp_fd == -1)
100  throw cms::Exception("TritonError") << "unable to munmap for shared memory key: " << this->name_;
101 
102  //unlink
103  int shm_fd = shm_unlink(this->name_.c_str());
104  if (shm_fd == -1)
105  throw cms::Exception("TritonError") << "unable to unlink for shared memory key: " << this->name_;
106 
107  this->closed_ = true;
108 }
#define TRITON_THROW_IF_ERROR(X, MSG)
Definition: triton_utils.h:75
TritonData< IO > * data_

◆ copyInput()

void TritonInputCpuShmResource::copyInput ( const void *  values,
size_t  offset 
)
inlineoverridevirtual

Reimplemented from TritonMemResource< IO >.

Definition at line 53 of file TritonMemResource.h.

53 {}

◆ copyOutput()

const uint8_t * TritonOutputCpuShmResource::copyOutput ( )
inlineoverridevirtual

Reimplemented from TritonMemResource< IO >.

Definition at line 54 of file TritonMemResource.h.

54 { return nullptr; }