CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Attributes
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, unsigned entry) override
 
void 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 ()
 

Protected Attributes

size_t sizeOrig_
 
- 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 62 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_, to_string(), and TRITON_THROW_IF_ERROR.

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

◆ ~TritonCpuShmResource()

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

Definition at line 94 of file TritonMemResource.cc.

94  {
95  close();
96 }

Member Function Documentation

◆ close()

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

Reimplemented from TritonMemResource< IO >.

Definition at line 99 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().

99  {
100  if (this->closed_)
101  return;
102 
103  TRITON_THROW_IF_ERROR(this->data_->client()->UnregisterSystemSharedMemory(this->name_),
104  "unable to unregister shared memory region: " + this->name_);
105 
106  //unmap
107  int tmp_fd = munmap(this->addr_, this->size_);
108  if (tmp_fd == -1)
109  throw cms::Exception("TritonError") << "unable to munmap for shared memory key: " << this->name_;
110 
111  //unlink
112  int shm_fd = shm_unlink(this->name_.c_str());
113  if (shm_fd == -1)
114  throw cms::Exception("TritonError") << "unable to unlink for shared memory key: " << this->name_;
115 
116  this->closed_ = true;
117 }
#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,
unsigned  entry 
)
inlineoverridevirtual

Reimplemented from TritonMemResource< IO >.

Definition at line 53 of file TritonMemResource.h.

53 {}

◆ copyOutput()

void TritonOutputCpuShmResource::copyOutput ( )
inlineoverridevirtual

Reimplemented from TritonMemResource< IO >.

Definition at line 54 of file TritonMemResource.h.

54 {}

Member Data Documentation

◆ sizeOrig_

template<typename IO >
size_t TritonCpuShmResource< IO >::sizeOrig_
protected

Definition at line 57 of file TritonMemResource.h.