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 ()
 
void closeSafe ()
 
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 78 of file TritonMemResource.cc.

References TritonMemResource< IO >::addr_, TritonCpuShmResource< IO >::close(), ALPAKA_ACCELERATOR_NAMESPACE::brokenline::constexpr(), TritonMemResource< IO >::data_, Exception, TritonMemResource< IO >::name_, hltrates_dqm_sourceclient-live_cfg::offset, TritonMemResource< IO >::size_, to_string(), and TRITON_THROW_IF_ERROR.

80  //mmap of size zero is required to fail by POSIX, but still need to have some shared memory region available for Triton
81  this->size_ = std::max<size_t>(this->size_, 1);
82 
83  //get shared memory region descriptor
84  int shm_fd = shm_open(this->name_.c_str(), O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
85  if (shm_fd == -1)
86  throw cms::Exception("TritonError") << "unable to get shared memory descriptor for key: " + this->name_;
87 
88  //extend shared memory object
89  int res = ftruncate(shm_fd, this->size_);
90  if (res == -1)
91  throw cms::Exception("TritonError") << "unable to initialize shared memory key " + this->name_ +
92  " to requested size: " + std::to_string(this->size_);
93 
94  //map to process address space
95  constexpr size_t offset(0);
96  this->addr_ = (uint8_t*)mmap(nullptr, this->size_, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, offset);
97  if (this->addr_ == MAP_FAILED)
98  throw cms::Exception("TritonError") << "unable to map to process address space for shared memory key: " +
99  this->name_;
100 
101  //close descriptor
102  if (::close(shm_fd) == -1)
103  throw cms::Exception("TritonError") << "unable to close descriptor for shared memory key: " + this->name_;
104 
105  TRITON_THROW_IF_ERROR(this->data_->client()->RegisterSystemSharedMemory(this->name_, this->name_, this->size_),
106  "unable to register shared memory region: " + this->name_,
107  true);
108 }
TritonData< IO > * data_
Definition: Electron.h:6
static std::string to_string(const XMLCh *ch)
#define TRITON_THROW_IF_ERROR(X, MSG, NOTIFY)
Definition: triton_utils.h:78
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 111 of file TritonMemResource.cc.

111  {
112  this->closeSafe();
113 }

Member Function Documentation

◆ close()

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

Reimplemented from TritonMemResource< IO >.

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

116  {
117  if (this->closed_)
118  return;
119 
120  TRITON_THROW_IF_ERROR(this->data_->client()->UnregisterSystemSharedMemory(this->name_),
121  "unable to unregister shared memory region: " + this->name_,
122  true);
123 
124  //unmap
125  int tmp_fd = munmap(this->addr_, this->size_);
126  if (tmp_fd == -1)
127  throw cms::Exception("TritonError") << "unable to munmap for shared memory key: " << this->name_;
128 
129  //unlink
130  int shm_fd = shm_unlink(this->name_.c_str());
131  if (shm_fd == -1)
132  throw cms::Exception("TritonError") << "unable to unlink for shared memory key: " << this->name_;
133 
134  this->closed_ = true;
135 }
TritonData< IO > * data_
#define TRITON_THROW_IF_ERROR(X, MSG, NOTIFY)
Definition: triton_utils.h:78

◆ copyInput()

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

Reimplemented from TritonMemResource< IO >.

Definition at line 54 of file TritonMemResource.h.

54 {}

◆ copyOutput()

void TritonOutputCpuShmResource::copyOutput ( )
inlineoverridevirtual

Reimplemented from TritonMemResource< IO >.

Definition at line 55 of file TritonMemResource.h.

55 {}

Member Data Documentation

◆ sizeOrig_

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

Definition at line 58 of file TritonMemResource.h.