#include <XrdSysShmem.hh>
|
static std::tuple< void *, size_t > | create (const std::string &name, size_t size) |
|
template<typename T > |
static std::tuple< T *, size_t > | get (const std::string &name) |
|
template<typename T > |
static std::tuple< T *, size_t > | make_array (const std::string &name, size_t count) |
|
template<typename T , typename... Args> |
static std::tuple< T *, size_t > | make_array (const std::string &name, size_t count, Args &&... args) |
|
Utility class for creating and obtaining shared emory
Definition at line 54 of file XrdSysShmem.hh.
◆ create()
static std::tuple< void *, size_t > XrdSys::shm::create |
( |
const std::string & |
name, |
|
|
size_t |
size |
|
) |
| |
|
inlinestatic |
Helper function for creating shared memory block
- Parameters
-
name | : name of the shared memory block (shared memory object should be identified by a name of the form /somename) |
size | : size of the shared memory segment |
- Returns
- : pointer to the shared memory and its size
Definition at line 65 of file XrdSysShmem.hh.
66 {
67 int fd = shm_open( name.c_str(), O_CREAT | O_RDWR, 0600 );
68 if( fd < 0 )
69 throw shm_error( errno );
71 {
72 if( errno != EINVAL )
73 throw shm_error( errno );
74 }
76 if(
fstat( fd, &statbuf ) < 0 )
77 throw shm_error( errno );
78 size = statbuf.st_size;
79 void *mem = map_shm( fd, size );
81 return std::make_tuple( mem, size );
82 }
References close, fstat, ftruncate, and stat.
Referenced by make_array(), and make_array().
◆ get()
template<typename T >
static std::tuple< T *, size_t > XrdSys::shm::get |
( |
const std::string & |
name | ) |
|
|
inlinestatic |
Helper function for getting shared memory block
- Parameters
-
name | : name of the shared memory block (shared memory object should be identified by a name of the form /somename) |
- Returns
- : pointer to the shared memory and its size
Definition at line 93 of file XrdSysShmem.hh.
94 {
95 int fd = shm_open( name.c_str(), O_RDWR, 0600 );
96 if( fd < 0 )
97 throw shm_error( errno );
99 if(
fstat( fd, &statbuf ) < 0 )
100 throw shm_error( errno );
101 size_t size = statbuf.st_size;
102 void *mem = map_shm( fd, size );
104 return std::make_tuple( reinterpret_cast<T*>( mem ), size );
105 }
References close, fstat, and stat.
◆ make_array() [1/2]
template<typename T >
static std::tuple< T *, size_t > XrdSys::shm::make_array |
( |
const std::string & |
name, |
|
|
size_t |
count |
|
) |
| |
|
inlinestatic |
Helper function for creating a shared memory block and constructing an array of objects of type T (constructed with default constructor) within the block.
- Parameters
-
name | : name of the shared memory block (shared memory object should be identified by a name of the form /somename) |
count | : size of the array |
- Returns
- : pointer to the shared memory and its size
Definition at line 119 of file XrdSysShmem.hh.
120 {
121 auto tpl =
create( name, count *
sizeof( T ) );
122 T* arr = reinterpret_cast<T*>( std::get<0>( tpl ) );
123 size_t size = std::get<1>( tpl );
124 for( size_t i = 0; i < count; ++i )
125 new( arr + i ) T();
126 return std::make_tuple( arr, size );
127 }
static std::tuple< void *, size_t > create(const std::string &name, size_t size)
References create().
◆ make_array() [2/2]
template<typename T , typename... Args>
static std::tuple< T *, size_t > XrdSys::shm::make_array |
( |
const std::string & |
name, |
|
|
size_t |
count, |
|
|
Args &&... |
args |
|
) |
| |
|
inlinestatic |
Helper function for creating a shared memory block and constructing an array of objects of type T (constructed with using arguments args) within the block.
- Parameters
-
name | : name of the shared memory block (shared memory object should be identified by a name of the form /somename) |
count | : size of the array |
args | : the arguments for the T constructor |
- Returns
- : pointer to the shared memory and its size
Definition at line 142 of file XrdSysShmem.hh.
143 {
144 auto tpl =
create( name, count *
sizeof( T ) );
145 T* arr = reinterpret_cast<T*>( std::get<0>( tpl ) );
146 size_t size = std::get<1>( tpl );
147 for( size_t i = 0; i < count; ++i )
148 new( arr + i ) T( std::forward<Args...>( args... ) );
149 return std::make_tuple( arr, size );
150 }
References create().
The documentation for this struct was generated from the following file: