25#ifndef SRC_XRDSYS_XRDSYSSHMEM_HH_
26#define SRC_XRDSYS_XRDSYSSHMEM_HH_
65 inline static std::tuple<void*, size_t>
create(
const std::string &name,
size_t size )
67 int fd = shm_open( name.c_str(), O_CREAT | O_RDWR, 0600 );
76 if(
fstat( fd, &statbuf ) < 0 )
78 size = statbuf.st_size;
79 void *mem =
map_shm( fd, size );
81 return std::make_tuple( mem, size );
93 inline static std::tuple<T*, size_t>
get(
const std::string &name )
95 int fd = shm_open( name.c_str(), O_RDWR, 0600 );
99 if(
fstat( fd, &statbuf ) < 0 )
101 size_t size = statbuf.st_size;
102 void *mem =
map_shm( fd, size );
104 return std::make_tuple(
reinterpret_cast<T*
>( mem ), size );
119 inline static std::tuple<T*, size_t>
make_array(
const std::string &name,
size_t count )
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 )
126 return std::make_tuple( arr, size );
141 template<
typename T,
typename... Args>
142 inline static std::tuple<T*, size_t>
make_array(
const std::string &name,
size_t count, Args&&... args )
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 );
161 inline static void*
map_shm(
int fd,
size_t size )
163 void *mem = mmap(
nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
164 if( mem == MAP_FAILED )
#define close(a)
Definition XrdPosix.hh:43
#define fstat(a, b)
Definition XrdPosix.hh:57
#define stat(a, b)
Definition XrdPosix.hh:96
#define ftruncate(a, b)
Definition XrdPosix.hh:65
Definition XrdClPollerBuiltIn.hh:28
Definition XrdSysShmem.hh:43
shm_error(int errcode)
Definition XrdSysShmem.hh:44
const int errcode
Definition XrdSysShmem.hh:47
const std::string errmsg
Definition XrdSysShmem.hh:48
Definition XrdSysShmem.hh:55
static void * map_shm(int fd, size_t size)
Definition XrdSysShmem.hh:161
static std::tuple< void *, size_t > create(const std::string &name, size_t size)
Definition XrdSysShmem.hh:65
static std::tuple< T *, size_t > make_array(const std::string &name, size_t count, Args &&... args)
Definition XrdSysShmem.hh:142
static std::tuple< T *, size_t > make_array(const std::string &name, size_t count)
Definition XrdSysShmem.hh:119
static std::tuple< T *, size_t > get(const std::string &name)
Definition XrdSysShmem.hh:93