12 #ifndef SST_CORE_INTERPROCESS_TUNNEL_SHM_PARENT_H 13 #define SST_CORE_INTERPROCESS_TUNNEL_SHM_PARENT_H 34 template <
typename TunnelType>
48 SHMParent(uint32_t comp_id,
size_t numBuffers,
size_t bufferSize, uint32_t expectedChildren = 1) :
53 memset(key,
'\0',
sizeof(key));
55 snprintf(key,
sizeof(key),
"/sst_shmem_%u-%" PRIu32
"-%d", getpid(), comp_id, rand());
58 fd = shm_open(filename.c_str(), O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
66 }
while ( (fd < 0) && (errno == EEXIST) );
69 fprintf(stderr,
"Failed to create IPC region '%s': %s\n", filename.c_str(), strerror(errno));
73 tunnel =
new TunnelType(numBuffers, bufferSize, expectedChildren);
74 shmSize = tunnel->getTunnelSize();
76 if ( ftruncate(fd, shmSize) ) {
78 fprintf(stderr,
"Resizing shared file '%s' failed: %s\n", filename.c_str(), strerror(errno));
82 shmPtr = mmap(
nullptr, shmSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
83 if ( shmPtr == MAP_FAILED ) {
85 fprintf(stderr,
"mmap failed: %s\n", strerror(errno));
88 memset(shmPtr,
'\0', shmSize);
89 tunnel->initialize(shmPtr);
97 munmap(shmPtr, shmSize);
117 std::string filename;
125 #endif // SST_CORE_INTERPROCESS_TUNNEL_SHM_PARENT_H virtual ~SHMParent()
Destructor.
Definition: shmparent.h:93
const std::string & getRegionName() const
returns name of the mmap'd region
Definition: shmparent.h:108
Definition: circularBuffer.h:20
SHMParent(uint32_t comp_id, size_t numBuffers, size_t bufferSize, uint32_t expectedChildren=1)
Parent/master manager for an IPC tunnel Creates a shared memory region and initializes a TunnelType d...
Definition: shmparent.h:48
Class supports an IPC tunnel between two or more processes via posix shared memory This class creates...
Definition: shmparent.h:35
TunnelType * getTunnel()
return the created tunnel pointer
Definition: shmparent.h:111