mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
|
A c++ class to manage a System V shared memory segment with memory mapping.
The associated functions create and/or attach to a shared memory segment. If a segment is created, a block of size sizeof(uintptr_t) is reserved where the address is stored. This address is used when subsequently attaching to the segment so that pointers stored in the block are valid, etc.
Definition at line 52 of file sharedMemSegment.hpp.
#include <ipc/sharedMemSegment.hpp>
Public Member Functions | |
void | initialize () |
Initialize the class. More... | |
key_t | setKey (const char *path, const int id) |
Set the key. More... | |
int | create (size_t sz) |
Create and attach to the segment. More... | |
int | attach (bool donot_set_addr=false) |
Attach to a segment without creating it. More... | |
int | detach () |
Detach from the segment. More... | |
Public Attributes | |
char | key_path [MX_IPC_KEYLEN] |
The path to use for key creation. More... | |
int | key_id |
The id to use for key creation. More... | |
key_t | key |
The shared memory key. More... | |
int | shmemid |
The shared memory id associated with the key. More... | |
void * | addr |
The base address of the segment. More... | |
size_t | size |
The size of the segment. More... | |
int | attached |
Flag indicating whether or not the segment is attached. More... | |
int mx::ipc::sharedMemSegment::attach | ( | bool | donot_set_addr = false | ) |
Attach to a segment without creating it.
If donot_set_addr == false, then the address is mapped to match that stored in the first uintptr_t of the segment.
donot_set_addr | if > 0 (true) then the address is not mapped to match that stored in the segment |
Definition at line 97 of file sharedMemSegment.cpp.
References addr, attached, key, shmemid, and size.
Referenced by create().
int mx::ipc::sharedMemSegment::create | ( | size_t | sz | ) |
int mx::ipc::sharedMemSegment::detach | ( | ) |
Detach from the segment.
Definition at line 160 of file sharedMemSegment.cpp.
void mx::ipc::sharedMemSegment::initialize | ( | ) |
key_t mx::ipc::sharedMemSegment::setKey | ( | const char * | path, |
const int | id | ||
) |
Set the key.
If path == 0, then the key is set directly to id, without using ftok.
path | is the full path to use in a call to ftok |
id | is the id number to use in a call to ftok |
Definition at line 47 of file sharedMemSegment.cpp.
void* mx::ipc::sharedMemSegment::addr |
The base address of the segment.
Definition at line 68 of file sharedMemSegment.hpp.
Referenced by attach(), create(), detach(), and initialize().
int mx::ipc::sharedMemSegment::attached |
Flag indicating whether or not the segment is attached.
Definition at line 74 of file sharedMemSegment.hpp.
Referenced by attach(), detach(), and initialize().
key_t mx::ipc::sharedMemSegment::key |
The shared memory key.
Definition at line 62 of file sharedMemSegment.hpp.
Referenced by attach(), create(), initialize(), and setKey().
int mx::ipc::sharedMemSegment::key_id |
The id to use for key creation.
Definition at line 59 of file sharedMemSegment.hpp.
Referenced by initialize(), and setKey().
char mx::ipc::sharedMemSegment::key_path[MX_IPC_KEYLEN] |
The path to use for key creation.
Definition at line 56 of file sharedMemSegment.hpp.
Referenced by setKey().
int mx::ipc::sharedMemSegment::shmemid |
The shared memory id associated with the key.
Definition at line 65 of file sharedMemSegment.hpp.
Referenced by attach(), create(), and initialize().
size_t mx::ipc::sharedMemSegment::size |
The size of the segment.
Definition at line 71 of file sharedMemSegment.hpp.
Referenced by attach(), and initialize().